Google 映射异步加载:除非显式打开,否则无法从异步加载的外部脚本写入文档
Google maps async load: It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened
这个只是向我发送了一些疑难解答,所以我认为它可能值得一种问答形式。
问:我正在尝试通过 API 异步加载 google 地图(类似于 this)
但是 google 地图加载器抱怨
Execute write on doc: It isn't possible to write into a document from
an asynchronously-loaded external script unless it is explicitly
opened
答:
您的 url 字符串可能只是有错字。
假设您使用了 args 并以
结束
url = https://maps.googleapis.com/maps/api/js?v=3.exp
?callback=callback
google 地图无法识别回调选项并获取使用调用 document.write() 的同步 js
脚本,而不是加载正确的异步版本。
你可以自己检查一下,如果加载后你有一个 maps.googleapis.com 脚本 maps/api/js?v=3.. 并且它包含一个包含 document.write()
的 getScript
调用,你就结束了错误的(同步)版本..
取自
在您的 api 请求中指定 &callback=someWindowFunction
并且 document.write
不会被调用
这个只是向我发送了一些疑难解答,所以我认为它可能值得一种问答形式。
问:我正在尝试通过 API 异步加载 google 地图(类似于 this) 但是 google 地图加载器抱怨
Execute write on doc: It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened
答: 您的 url 字符串可能只是有错字。 假设您使用了 args 并以
结束url = https://maps.googleapis.com/maps/api/js?v=3.exp
?callback=callback
google 地图无法识别回调选项并获取使用调用 document.write() 的同步 js
脚本,而不是加载正确的异步版本。
你可以自己检查一下,如果加载后你有一个 maps.googleapis.com 脚本 maps/api/js?v=3.. 并且它包含一个包含 document.write()
的 getScript
调用,你就结束了错误的(同步)版本..
取自
在您的 api 请求中指定 &callback=someWindowFunction
并且 document.write
不会被调用