Wicket
  1. Wicket
  2. WICKET-3669

<script> element in Ajax requests is executed twice in Opera 11

    Details

      Description

      I have component with behavior which adds <script> element in Behavior.onComponentRendered() to respons. This javascript is to be processed in browser when component is rendered. This works pretty well when component is rendered during standard HTTP request. But when the same code is called from Ajax request, this script runs on browser two times!

      There is some magic in Ajax request processing in wicket-ajax.js: only for Opera and IE these <script> elements from responses are added to HTML and page <header> element as well. Comment says that this is workaround for these browsers, maybe in older versions of Opera dynamically adding element into HTML doesn't run <script> elements within, but now could be obsolete.

      1. testcase-WICKET-3669.tar.gz
        8 kB
        Martin Schayna
      2. testcase-WICKET-3669-second.tar.gz
        8 kB
        Martin Schayna

        Activity

        Hide
        Martin Grigorov added a comment -

        Fixed with the usage of JQuery to replace the DOM.
        Tested with Opera 11.60 on Ubuntu.

        Show
        Martin Grigorov added a comment - Fixed with the usage of JQuery to replace the DOM. Tested with Opera 11.60 on Ubuntu.
        Hide
        Martin Schayna added a comment -

        There are no solution out there. Maybe fix for 1.4.x can be unnecessary, but the same fix for 1.5 doesn't work...

        Show
        Martin Schayna added a comment - There are no solution out there. Maybe fix for 1.4.x can be unnecessary, but the same fix for 1.5 doesn't work...
        Hide
        Martin Schayna added a comment -

        OK, I see that my simple "fix" doesn't work in Opeara 9, hm.

        I upload second test case right now, it demonstrates where your first fix failed. I hope it should be resolved in Wicket 1.4. Thanks for your support.

        Show
        Martin Schayna added a comment - OK, I see that my simple "fix" doesn't work in Opeara 9, hm. I upload second test case right now, it demonstrates where your first fix failed. I hope it should be resolved in Wicket 1.4. Thanks for your support.
        Hide
        Martin Schayna added a comment -

        Second test case, where first fix won't work.

        Show
        Martin Schayna added a comment - Second test case, where first fix won't work.
        Hide
        Martin Grigorov added a comment -

        Which second case you mean ?

        We know that Opera 11 is not Opera 9. The same is valid for Safari 5 which is treated as Safari 3.
        If we do your "fix" then some user of Opera 9/10 may complain that it doesn't work ...
        We have plans to use JQuery for the functionality needed by wicket-ajax.js so hopefully this will solve all such issues. But this is planned for Wicket 1.6/1.7.

        Show
        Martin Grigorov added a comment - Which second case you mean ? We know that Opera 11 is not Opera 9. The same is valid for Safari 5 which is treated as Safari 3. If we do your "fix" then some user of Opera 9/10 may complain that it doesn't work ... We have plans to use JQuery for the functionality needed by wicket-ajax.js so hopefully this will solve all such issues. But this is planned for Wicket 1.6/1.7.
        Hide
        Martin Schayna added a comment -

        I'm afraid this ticket must be reopened.

        Fix works only for components which has <script> element on its first level (as seen in first test case). When component with script behavior is added to another component (Panel e.g.) and this parent component is changed in AJAX request, script is executed twice in browser again. See my second test case.

        I have tried this simple solution: in replaceOuterHtml() method in wicket-ajax.js comment out test for Opera browser, so in this case is executed same code as in Gecko browsers. It works for me in all of my real cases (pretty large application which heavily uses Wicket). It seems like modern Opera versions are more compatible with Gecko than older versions.

            if (Wicket.Browser.isIE()) {  //-- don't do this for Opera  || Wicket.Browser.isOpera()) {		
            	Wicket.replaceOuterHtmlIE(element, text);				
            } else if (Wicket.Browser.isSafari() ) {
            	Wicket.replaceOuterHtmlSafari(element, text);    	
            } else /* GECKO */ {
               ...
        
        Show
        Martin Schayna added a comment - I'm afraid this ticket must be reopened. Fix works only for components which has <script> element on its first level (as seen in first test case). When component with script behavior is added to another component (Panel e.g.) and this parent component is changed in AJAX request, script is executed twice in browser again. See my second test case. I have tried this simple solution: in replaceOuterHtml() method in wicket-ajax.js comment out test for Opera browser, so in this case is executed same code as in Gecko browsers. It works for me in all of my real cases (pretty large application which heavily uses Wicket). It seems like modern Opera versions are more compatible with Gecko than older versions. if (Wicket.Browser.isIE()) { //-- don't do this for Opera || Wicket.Browser.isOpera()) { Wicket.replaceOuterHtmlIE(element, text); } else if (Wicket.Browser.isSafari() ) { Wicket.replaceOuterHtmlSafari(element, text); } else /* GECKO */ { ...
        Hide
        Martin Grigorov added a comment -

        Fixed.
        Tested on FF4, Chrome 12, IE8 and Opera 11

        Show
        Martin Grigorov added a comment - Fixed. Tested on FF4, Chrome 12, IE8 and Opera 11
        Hide
        Martin Schayna added a comment -

        quickstart for WICKET-3669

        Opera 11 shows alerts two times with same number

        Show
        Martin Schayna added a comment - quickstart for WICKET-3669 Opera 11 shows alerts two times with same number

          People

          • Assignee:
            Martin Grigorov
            Reporter:
            Martin Schayna
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development