簡體   English   中英

在FireFox中執行注入的JavaScript

[英]Execute injected javascript in FireFox

我在網站上注入了一些代碼(換句話說, http:// localhost / FibReactHello /#的返回值):

<div id="reactAppEntryPoint">
  <script src="http://localhost/FibReactHello/scripts/bundle.js"></script>
</div>

正如我在Chrome和IE11中所期望的那樣,此JS已運行並轉換為我的react應用程序。 在Firefox中,不執行JS。 它只是像木頭上的顛簸一樣坐在那里。 JS應該導致生成了一些HTML,從而為我提供了任意網站內容。

這是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>

我將Ajax調用更改為dataType“腳本”,而不是“ html”。 也直接指向我的bundle.js文件。 該腳本在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
            });

在IE中,這解決了獲取腳本的問題。 但是在我的情況下,我的bundle.js需要一個polyfill來學習IE如何運行jabbascrept:

使用babel后在IE中未定義“符號”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM