Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Microsoft Edge browser中同步调用java脚本文件失败。_Javascript_Html_Microsoft Edge_Java Scripting Engine - Fatal编程技术网

Javascript 在Microsoft Edge browser中同步调用java脚本文件失败。

Javascript 在Microsoft Edge browser中同步调用java脚本文件失败。,javascript,html,microsoft-edge,java-scripting-engine,Javascript,Html,Microsoft Edge,Java Scripting Engine,我有一个abc.html页面,我在其中调用两个javascript文件,如下head标记中所示:- <head> <script src="script_files/1.js"></script> <script src="script_files/2.js"></script> </head> 现在,当我加载abc.html时,我需要3.js文件。 它将调用3.js ajax,但在完成ajax调用之前,它将提交到

我有一个abc.html页面,我在其中调用两个javascript文件,如下head标记中所示:-

<head>
  <script src="script_files/1.js"></script>
  <script src="script_files/2.js"></script>
</head>
现在,当我加载abc.html时,我需要3.js文件。 它将调用3.js ajax,但在完成ajax调用之前,它将提交到2.js file方法


此问题仅在Microsoft Edge浏览器中出现。

我建议先阅读此主题:

编辑:正如friendly指出的那样,MS Edge自版本12以来确实支持
onreadystatechange
事件,但似乎带有
content=“ie=Edge”
元标记的IE11必须使用
onload
事件

如果您的脚本是web资源,那么您别无选择,只能向每个依赖项添加
onload
事件处理程序。它可能与计数器的功能相同,以了解它们何时全部加载。然后动态加载所有其他脚本

如果可以作为本地资源访问脚本,则可以通过以下方式加载脚本:

var sPath = 'Local_path\\script.js';
var oFSO = new ActiveXObject('Scripting.FileSystemObject');
var oFile = oFSO.OpenTextFile(sPath, 1, true, 0); // ForReading, ANSI
var oScript = document.createElement('script');
oScript.type = 'text/javascript';
oScript.text = oFile.ReadAll();
document.head.appendChild(oScript); // Sync loading
oFile.Close();

它以文本文件的形式读取脚本,然后以内联块的形式加载其内容,因此即使在MS Edge中,也会立即执行此操作。

如何运行ajax调用?只是在1.js文件中显示?或者在ondocumentready事件上,或者在onload上?我正在ondocumentready事件上运行ajax调用。Edge从版本12开始就支持
onreadystatechange
事件。谢谢你的洞察力,我把它添加到主题中了!
var sPath = 'Local_path\\script.js';
var oFSO = new ActiveXObject('Scripting.FileSystemObject');
var oFile = oFSO.OpenTextFile(sPath, 1, true, 0); // ForReading, ANSI
var oScript = document.createElement('script');
oScript.type = 'text/javascript';
oScript.text = oFile.ReadAll();
document.head.appendChild(oScript); // Sync loading
oFile.Close();