ICEfaces
  1. ICEfaces
  2. ICE-3470

Use of javascript: protocol in href attribute of an anchor tag causes IE to stop working

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.7.1
    • Fix Version/s: 1.7.2
    • Component/s: Bridge
    • Labels:
      None
    • Environment:
      IE
    • Support Case References:
      Show
      https://www.icesoft.ca:4443/supportilla/show_bug.cgi?id=4552
    • Workaround Exists:
      Yes
    • Workaround Description:
      Hide
      Use the onclick handler rather than the href attribute. Instead of:

          <a href="javascript:stay();">Stay (via javascript: from href)</a> (this one triggers onbeforeunload with IE)<br/>

      Use:

          <a onclick="stay();" href="#">Stay (via onclick)</a> <br/>
      Show
      Use the onclick handler rather than the href attribute. Instead of:     <a href="javascript:stay();">Stay (via javascript: from href)</a> (this one triggers onbeforeunload with IE)<br/> Use:     <a onclick="stay();" href="#">Stay (via onclick)</a> <br/>

      Description

      if you use the javascript: protocol in the href attribute of an anchor, it causes an ICEfaces page running in IE to stop working. If you move the code into the onclick of the anchor, it seems to be okay - this is the suggested workaround. Here's a snippet from the test case to illustrate:

      This is bad:

          <a href="javascript:stay();">Stay (via javascript: from href)</a> (this one triggers onbeforeunload with IE)<br/>

      This is okay (of course you don't need to use the javascript: protocol if you use the onclick handler):

          <a onclick="stay();" href="#">Stay (via onclick)</a> <br/>

      If your actions in the script triggered event actually causes you to leave the page, the event fires twice in IE:

          <a href="javascript:leave();">Leave (via javascript: from href)</a><br/>

      The problem is that use of the javascript: protocol in IE triggers the beforeunload event to fire (but not the unload event). The ICEfaces JavaScript bridge relies on the event to do some cleanup operations. Because the bridge gets cleaned up, further action on the page will not work.
      1. js.html
        2 kB
        Deryk Sinotte

        Issue Links

          Activity

          Deryk Sinotte created issue -
          Deryk Sinotte made changes -
          Field Original Value New Value
          Support Case References https://www.icesoft.ca:4443/supportilla/show_bug.cgi?id=4552
          Assignee Deryk Sinotte [ deryk.sinotte ]
          Hide
          Deryk Sinotte added a comment -

          A simple test case that shows the how the onbeforeunload event is fired in IE when using the the javascript: protocol in the href attribute of an anchor tag.

          Show
          Deryk Sinotte added a comment - A simple test case that shows the how the onbeforeunload event is fired in IE when using the the javascript: protocol in the href attribute of an anchor tag.
          Deryk Sinotte made changes -
          Attachment js.html [ 11214 ]
          Deryk Sinotte made changes -
          Link This issue is duplicated by ICE-1915 [ ICE-1915 ]
          Deryk Sinotte made changes -
          Link This issue is duplicated by ICE-3354 [ ICE-3354 ]
          Hide
          Deryk Sinotte added a comment -

          The suggested work arounds are recommended to avoid this issue.

          Show
          Deryk Sinotte added a comment - The suggested work arounds are recommended to avoid this issue.
          Deryk Sinotte made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Fix Version/s 1.7.2 [ 10130 ]
          Resolution Won't Fix [ 2 ]
          Hide
          Deryk Sinotte added a comment -

          Just to follow up, I did all my testing on IE 6. Not sure if the behaviour is significantly different on IE 7. I couldn't find anything in the incoming event attributes (for beforeunload event) that you could query to uniquely determine whether the javascript: protocol is used or not. Apparently everything in the event is just null or undefined. If we could find something distinct, we could do something to handle it (like not unloading all of our stuff and/or logging something).

          The only way I could find of working around this was to add a flag using another event (onclick seems to be fired before onbeforeunload) The flag could be checked and then reset in the handler for beforeunload. But this is extremely clumsy and requires that the user implement a second event on their element (something that might not even be possible in the media component case).

          <a href="javascript: stay();" onclick="setJSProtocolFlag();">Stay (via javascript: from href, setting protocol flag)</a><br/>

          Show
          Deryk Sinotte added a comment - Just to follow up, I did all my testing on IE 6. Not sure if the behaviour is significantly different on IE 7. I couldn't find anything in the incoming event attributes (for beforeunload event) that you could query to uniquely determine whether the javascript: protocol is used or not. Apparently everything in the event is just null or undefined. If we could find something distinct, we could do something to handle it (like not unloading all of our stuff and/or logging something). The only way I could find of working around this was to add a flag using another event (onclick seems to be fired before onbeforeunload) The flag could be checked and then reset in the handler for beforeunload. But this is extremely clumsy and requires that the user implement a second event on their element (something that might not even be possible in the media component case). <a href="javascript: stay();" onclick="setJSProtocolFlag();">Stay (via javascript: from href, setting protocol flag)</a><br/>
          Ken Fyten made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Assignee Deryk Sinotte [ deryk.sinotte ]

            People

            • Assignee:
              Unassigned
              Reporter:
              Deryk Sinotte
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: