[英]Execute injected javascript in FireFox
I'm injecting a bit of code into my website (in other words the return value of http://localhost/FibReactHello/# ): 我在网站上注入了一些代码(换句话说, http:// localhost / FibReactHello /#的返回值):
<div id="reactAppEntryPoint">
<script src="http://localhost/FibReactHello/scripts/bundle.js"></script>
</div>
This JS is run and converted to my react application as I would expected in both Chrome and IE11. 正如我在Chrome和IE11中所期望的那样,此JS已运行并转换为我的react应用程序。 In Firefox the JS is not executed. 在Firefox中,不执行JS。 It just sits there like a bump on a log. 它只是像木头上的颠簸一样坐在那里。 The JS should have caused some HTML to be generated giving me arbitrary site content. JS应该导致生成了一些HTML,从而为我提供了任意网站内容。
Here's the jQuery: 这是jQuery:
<div id="appEntrypt">
<button onclick="alertMe(event);">Inject React into Boost</button>
</div>
<script>
function alertMe(e) {//crappy named function
//e.preventDefault();
console.log('js works');
var url = "http://localhost/FibReactHello/#";
resetState();
$.ajax({
url: url, success: function (result) {
$("#appEntrypt").html(result);
write(result);
},
async: true
});
/*
$.get(url, function (data) {
$("#appEntrypt").html(data);
write(data);
});*/
return null;
}
function write(data) {
console.log(data);
};
function resetState() {
document.getElementById('appEntrypt').innerHTML = "";
};
</script>
I changed my Ajax call to dataType 'script' as opposed to 'html'. 我将Ajax调用更改为dataType“脚本”,而不是“ html”。 Also pointed directly to my bundle.js file. 也直接指向我的bundle.js文件。 The script executes in Chrome and Firefox. 该脚本在Chrome和Firefox中执行。
$.ajax({
url: devUrl,
success: function (result) {
console.log("successfully got script")
},
error: function (xhr, status, errorThrown) {
var output = "Error: " + errorThrown + ' status: ' + status + ' statusText: ' + xhr.statusText
console.log("failed to get script: " + output);
},
contentType: 'application/javascript',//IE
dataType: 'script',
cache: false,//required for IE
crossDomain: true,//required for IE
});
In IE this solved the issue of grabbing the script. 在IE中,这解决了获取脚本的问题。 But in my case my bundle.js needed a polyfill to learn IE how to run jabbascrept: 但是在我的情况下,我的bundle.js需要一个polyfill来学习IE如何运行jabbascrept:
'Symbol' is undefined in IE after using babel 使用babel后在IE中未定义“符号”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.