Javascript top.frames(0).location set works sporadically in IE9

Unanswered Javascript top.frames(0).location set works sporadically in IE9

  • lunedì 7 maggio 2012 12:11
     
      Contiene codice

    I have some javascript code that re-sets a frame location upon load:

    <script type="text/javascript" language="javascript">
    	var qs = '<%= Request.QueryString("LoanID") %>'
    	
    	if(!(qs=='0') && !(qs==''))
    	{
    		top.frames("left").frames("left1").location = top.frames("left").frames("left1").location + '?LoanID=' + qs;
    	}
    	else
    	{
    		top.frames("left").frames("left1").location = top.frames("left").frames("left1").location + '?LoanID=' + <%=Session("LoanID") %>;
    	}
    </script>
    

    Ever since our clients have started moving to IE9 this code sometimes works, and sometimes does not work at all.  I've read a few threads about caching but the clients' "Check for newer versions" option is set to "everytime I visit the page", and we have no other caching turned on.  Any idea why this is happening and what I can do to make sure the code executes properly every time?

    TIA

    -VG


    VG_mnet

Tutte le risposte

  • lunedì 7 maggio 2012 17:11
     
     

    What happens when it "does not work at all", do you see script errors?

    If that is the case then I suggest to change to bracket notation e.g.

      top.frames["left"].frames["left1"].location = top.frames["left"].frames["left1"].location + '?LoanID=' + qs;

    as I think the function call syntax on the frames object is not supported in IE 9 in standards mode so perhaps some of your pages are rendered in that mode and that way all you get is script errors.


    MVP Data Platform Development My blog

  • lunedì 7 maggio 2012 17:32
     
     

    Hi Martin, thanks for the advice.  We did not get any script errors, but then again, IE9 apparently never shows script errors.  I do know the F12 trick to debug javascript errors but every time I try it, it works properly, and there are no errors.

    I have made the change you suggested and will let you know if it fixes the problem.

    Thank you

    -VG


    VG_mnet


    • Modificato VG_mnet lunedì 7 maggio 2012 17:32
    •  
  • martedì 8 maggio 2012 23:11
     
     

    search your scripts for 'console.log'

    replace it with

    if(window.console){console.log('message to log');}


    Rob^_^

  • mercoledì 9 maggio 2012 11:47
     
     

    Rob, I don't see how this is in any way relevant to my post.  First, this is a web page, not a windows app, and I didn't mention anything about logging to a console.  Am I missing something, or did you post to the wrong thread?

    Thanks

    -VG


    VG_mnet

  • venerdì 11 maggio 2012 11:33
     
     

    Martin, it came to light yesterday that changing from parentheses to brackets did NOT fix the problem.  I was able to see it happen to one of my users, so I immediately hopped on the IIS logs to see what I could there, and after the page with this JS was listed as a GET, the page that I'm trying to reload on the other iFrame did NOT display as a GET at all (I expected it would load that iFrame, but the qs may have been missing, so that was a surprise).  That tells me neither the If or the else executed at all.  If neither executed, usually that's due to a syntax error, but I don't understand how that could happen.  Any other ideas?

    TIA
    -VG


    VG_mnet

  • venerdì 11 maggio 2012 12:04
     
     

    Well if there are errors you should be able to have IE report them, otherwise it is very hard for anyone hear to tell what goes wrong. My previous suggestion was simply a guess as to what could be one possible cause of the problem.

    Another problem I see is that your script seems to be inline script executed during page load and trying to access other frames. I don't know which documents are loaded or reloaded by I think there is no guarantee that frame windows are created in the same order on each load or in the order they appear in the outer document so that could be one other cause of the code failing to set a frame location, that sometimes the other frame is not yet accessible.

    The line

    var qs = '<%= Request.QueryString("LoanID") %>'

    could also cause a client-side script syntax error if the server side code (Request.QueryString("LoanID")) returns something containing a single quote. In that case the whole script block will fail to be parsed and executed successfully by the script engine.

    So without more information I can only suggest to look for error messages by IE.


    MVP Data Platform Development My blog

  • venerdì 11 maggio 2012 17:11
     
     

    Thank you Martin.  I did consider the single quote issue, but I'm fairly certain there wouldn't be one in the QS parameter. 

    The frame load order is an interesting point I hadn't thought of, although it is still strange that this only started occurin in IE9.  If I were to instead make a function that I call from body onload, would that wait for all frames to load before executing? Actually, I'm not sure that would be true either. 

    As for looking for having IE report error messages, aside from being present when the strange non-load occurs and taking over my user's machine to run through F12 debugging, is there any other way to capture, maybe even log, a javascript error?  Is there anything that my users can do to find out if there is a Javascript error message so they can send it to me, if it happens to them while I am not there?  I used to be able to tell them - click on the yellow triangle in the bottom-left corner, and take a screenshot of the window that pops up, but in IE9 there is no more yellow triangle icon. :(

    Thanks again.

    -VG


    VG_mnet

  • venerdì 11 maggio 2012 17:25
     
     

    Hitting F12 and looking at the "console" tab should display script errors. And then it is possible to copy the error message as text with right click -> copy I think.

    As for the frames, I don't know if anything has changed in IE 9. And no, body onload in a frame does not ensure other frames are loaded respectively accessible. Before following up on that frames issue I would rather suggest to try to get an error message from IE 9, as then it should be easier to make more than a guess as to what goes wrong.

    MVP Data Platform Development My blog