Having a string with several tags given, i have to insert them – if possible at once, without parsing the string to extract the separate scripts:
decodeURIComponent(“%3Cscript%20src%3D%27%2F%2Ftest%2Fdg-48119-137488.js%27%20async%20defer%3E%3C%2Fscript%3E%3Cscript%20src%3D%27%2F%2Ftest2%2Feg-48119-137488.js%27%20async%20defer%3E%3C%2Fscript%3E”).replace(/+/g,”%20″);
I tried with createElement(“DIV”), adding the string’s content with .innerHTML and appendChild(theDIV). The html content looks fine, but the scripts did not load 🙁
What else can I do to get the script post-loaded (without parsing the string before)?
I think this isn’t working because the code you posted uses an invalid regular expression.
+is a reserved character in regex. Try instead using.replace(/\+/g,"%20");(note the escaped
+).