代码:
var scriptFile = document.createElement('script');
scriptFile.setAttribute("type","text/javascript");
scriptFile.setAttribute("src",'http://api.map.baidu.com/api?type=quick&ak=o9B4Ol99j9NcBXSu5nFTR7uI&v=1.0');
document.getElementsByTagName("head")[0].appendChild(scriptFile);
最后要添加到head里的时候,报这个错:Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
我其它普通的js是可以的,但是百度的这个似乎不行,请问解决方法,或者其它添加js的方法(使用ajax的方法也行,只要是原生js就好了)
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
2楼正解!
错误提示已经说得很明白了:异部引入的外部文件在document中write,It isn't possible.
至于unless it is explicitly opened.怎么做,我不知道...
同域的异步外链js是可以的