开发者

Firefox4/5 not running JS attached to an AJAX response using HTML_AJAX pear library

I am using the HTML_AJAX package in PEAR (admittedly an old library, but it has worked fine for me for a couple of years and I don't want to leave my infrastructure).

The problem I am having is that with the introduction of Firefox 4, and now also Firefox 5, JavaScript that is included in responses using HTML_AJAX.replace(div_target, request_page) [API is to replace div_target with the response from request_page] has stopped working.

It works fine on Chrome, IE9, Android, iPhone, etc. but not FF4/5.

Is this some sort of new feature, security mechanism, or just a plain old bug? If it's a bug, is it a bug with HTML_AJ开发者_如何学GoAX (i.e. you can do it with jQuery?) or is this something FF needs to fix?

Example.

This page exists:

<script type="text/javascript" language="JavaScript">
    function do_replace(){
        HTML_AJAX.replace("something", "index.php?key=value"); // index.php will have html mixed with JS and paste it to the div "something".
    }
</script>
<div id="something" onclick="javascript:do_replace()">This text is to be replaced</div>

And this is index.php:

BLA BLA BLA some text maybe a <div> or something
<script type="text/javascript" language="JavaScript">
    alert("this has worked before, but stopped working on FF4&5 still works on Chrome Android etc.");
</script>

I tried finding the answer to this by searching but couldn't find anything conclusive. I appreciate any help I can get on this.

BR Erik.


This is how I solved it.

Replace

    var good_browser = (navigator.product == 'Gecko');

With

    if(navigator.product == 'Gecko'){
        var regex_gb = /Firefox[\/\s](\d+\.\d+)/;
        if(regex_gb.test(navigator.userAgent)){
         var ffversion = new Number(RegExp.$1);
            if(ffversion >= 4){
                var good_browser = false;
            }else{
                var good_browser = true;
            }
        }else{
            var good_browser = true;
        }
    }else{
        var good_browser = false;
    }

in the 3 files

HTML_AJAX.js
HTML_AJAX_lite.js
util.js.


Util.setInnerHtml detects gecko and uses a hack for a performance win. If you remove that check things will be fixed. Im not sure when I will have a chance to get this patched and release, but it should be a quick change to make.


You need to set :

var good_browser = false;

At 3 places in 3 files for it to work. For me the 3 files were :

  • HTML_AJAX.js
  • HTML_AJAX_lite.js
  • util.js.

Then it worked.


I'm having the same problem with the HTML_AJAX package in PEAR. None of the inline script tags are executed by Firefox 4 or 5 after an AJAX call. Its seem to me that the HTML_AJAX is breaking the HTML5 security standard related with inline scripting.

For Firefox 4, adding an empty tag at the end of the file with the script tag solved the problem, but that was only an ugly work-around that was actually a bug on FF4 that was fix for FF5.

I don't want to change the framework but HTML_AJAX is a long way behind the new ones. Maybe we haven't found the real problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜