Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts

    window.onload not working in IE

    Hello,

    I have a bit of javascript that automatically loads Shadowbox on load.

    It works perfectly in Firefox, Chrome but NOT IE.

    If I put a standard link to open Shadowbox does work in IE, so it's not the shadowbox, it's definitely the window.onload bit which isn't working.

    Here is my code.

    Code:
    <link rel="stylesheet" type="text/css" href="shadowbox/shadowbox.css">
    <script type="text/javascript" src="shadowbox/shadowbox.js"></script>
    <!--this bit is for a link to open the Shadowbox from a link elsewhere on the page -->
    <script type="text/javascript">
    Shadowbox.init({players:['swf']});
    </script>
    
    <script type="text/javascript">
               window.onload = function() {
                     Shadowbox.open({
                               content: 'flash/flash002.swf',
                               player:  "swf",
                               title:   'Open Shadowbox',
                               width:   1200,
                               height:  800,
                               
                     });
    				
    
               };
    
          </script>
    This DOES work though, so I know it's not the Shadowbox with the issue

    Code:
    <a href="flash/flash002.swf" rel="shadowbox;height=800px;width=1200px">Open Shadowbox</a>
    Really appreciate your help!

    Nicola

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    Why didn't you put the Shadowbox.init into the window.onload? I bet it would work then .. window.onload has been a well known standard for years, even for IE. So the problem cannot be related to window.onload

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Hi - Thanks for your reply.

    I can add it but that code works in every other browser I can test in just as it is, so there is something different about IE. The code works ok otherwise.

    Let me have a go and I'll let you know.

    Nicola

  • #4
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Hi - I tried this and it didn't work.

    Even if I put a really simple pop up into the window.onload it doesn't work either in IE - although it does in all other browsers.

    Nicola

  • #5
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Hi - I've also run the code using the Error checker in Firefox which usually flags up any coding issues, no errors.

    I've done some further testing - the issue is ONLY with IE9. IE8 works perfectly.

    Just in case this helps isolate the issue.

    Thanks,

    Nicola

  • #6
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    What is the !DOCTYPE of your document?

  • #7
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    It's strict.

    Thanks again!

    Nicola

  • #8
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    As I don't have IE9, I am not able to test. window.onload works perfectly well on my IE8 and I never heard about problems with window.onload on IE9 ... maybe someone else can help?

  • #9
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Thanks! It works fine in IE8 here too, how frustrating!!

    Really appreciate your time! I found this:

    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

    Which suggests that maybe I need to use a slightly different way for IE9?

    Nicola

  • #10
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Why not just put all that JavaScript at the bottom of the page (where JavaScript belongs) and where you don't need to test for the page having finished loading when all you need to know is that the HTML has loaded (which it will have if the script is at the bottom of the page).
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #11
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    ... except for the images and other binary content ... window.onload will also wait for those items to finish loading. Moving Javascript to the bottom of the page will not be equivalent to that.

  • #12
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by devnull69 View Post
    ... except for the images and other binary content ... window.onload will also wait for those items to finish loading. Moving Javascript to the bottom of the page will not be equivalent to that.
    Yes it will since browsers will not download JavaScript while other files are downloading. While browsers can download up to eight files at a time they doso aonly provided none of the files are JavaScript. When they get a request to download JavaScript they wait until after all the currently downloading files finsh downloading then download the JavaScript by itself and only when the Javascript finishes downloading will they resume downloading the other files eight at a time. So with the script at the bottom of the page it is almost certain that all the other files have already downloaded sine they will all have been requested first and the browser cannot start downloading the JavaScript until the files already downloading finish.

    Only by adding an async attribute to the script tag will those few browsers that understand that attribute actually start downloading the JavaScript before all the other files finish downloading.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •