当将responseHTML与XHR结合使用时,Firefox会在加载的responseHTML中执行javascript,而chromium则不会。如果我添加一个脚本来解析和执行脚本,它将在 chromium 上运行,但它们会在 Firefox 中执行两次。除了通过代理嗅探之外,您知道如何知道浏览器是否会执行加载的脚本吗? PS:我使用的 JS 框架不是 jQuery 或 Prototype 或任何东西
最佳答案
这是我第n次回答这个问题了:)
// response is the data returned from the server
var response = "html\<script type=\"text/javascript\">alert(\"foo\");<\/script>html";
var reScript = /\<script.*?>(.*)<\/script>/mg;
response = response.replace(reScript, function(m,m1) {
eval(m1); //will run alert("foo");
return "";
});
alert(response); // will alert "htmlhtml"
关于javascript - 在responseHTML中执行JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3129393/