Dynamically Adding Script Tags with Uncontrolled Source Content
Creating a script tag with a source external to your control can pose a challenge when the content includes code that utilizes document.write(). As noted, simply appending the script tag in the
cannot support such content.To overcome this, consider the following solution:
var my_awesome_script = document.createElement('script'); my_awesome_script.setAttribute('src','http://example.com/site.js');
document.head.appendChild(my_awesome_script);
This method effectively includes the external script dynamically, allowing the included code to execute without any issues.
The above is the detailed content of How to Dynamically Include Scripts with Uncontrolled `document.write()` Content?. For more information, please follow other related articles on the PHP Chinese website!