asynchronous loading js does not allow the use of document write solution
to recommend a cat smoking website: love cat family (http://15cat.com), I hope you like
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);
When you finally want to add it to the head, chrome comes up with the following warning.
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.
What is this?
PS: An error in chrome in console (a red error mark) will prevent the script from executing after the error, a warning (yellow exclamation mark) just won’t execute where it was warned.
Solution.
This occurs because the code introduced contains a document.write method, and asynchronously loaded js is not allowed to use the document.write method.
Since the document has been loaded and parsed, the document stream is closed.
So the js you load asynchronously can no longer write into the document, such as using document.write.
So two direct links can be introduced.
var usel = '<script src="';
usel += gds[0].imageurl;
usel += '"></script>';
document.write(usel);
Read More:
- JS error: permission denied to access property ‘document’— document.domain -The same source strategy of JavaScript
- Solution: vs currently does not hit the breakpoint and has not loaded any symbols for the document
- After node.js is installed, use the instruction node version in vscode to show that it is not an external or internal instruction. The solution is as follows:
- node.js Error: write epipe problem solved!
- Windows can’t delete the file, indicating that it is in use. (release of document occupation)
- Could not write JSON: write javaBean error, fastjson version x.x.x, class
- events.js:160 throw er; // Unhandled ‘error’ event ^ Error: write after end at Serv
- Content rendering error: a solution to the problem of zero Download document cannot be opened
- A solution to the error of asynchronous socket error 10053 in C + + Builder
- React bootstrap loading and how to use modules
- C language write() function analysis: write failed bad address
- Common error: uncaught typeerror: document.getElementsByClassName (…).addEventListener is not a function
- Solution of “do not use ‘new’ for side effects” for eslint verification of Vue project
- Use less.js to verify and report an error in the Vue file of vscode
- How to use Latex to Write Matrices
- [Linux] e297: write error in swap file solution
- “Could not import PIL.Image . The use of array_ to_ The solution of img requires PIL. “
- Unable to read scheme document‘ http://www.springframework.org/schema/spring-context.xsd The solution to the problem
- The document “ostream” could not be saved. You don’t have permission
- about jQuery.js The solution to always reporting errors