onunload event handler not firing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • banning
    New Member
    • Aug 2007
    • 42

    onunload event handler not firing

    [code=javascript]<!-- Google maps has a tendency to wreck things. Load it LAST! It can interfere with other stuff loading -->
    <script src="http://maps.google.com/maps?file=api&a mp;v=2&amp;key= ABQIAAAArSHIvK5 GjeMNDX4RccZ9Mh QrmFaz44GnQXOo2 7J3f2GHeKYI9xTi 9qFD_LdIDqtpRDv M4YWE8kto-A" type="text/javascript"></script>

    <script type='text/javascript'>
    function setImage() {
    document.getEle mentById('event LogoDiv').inner HTML='<a href="http://www.doughxpress .com/staging"><img src="http://www.doughxpress .com/staging/imgs/headerLOGO.jpg" alt="HIX Corporation"></img></a>';
    }
    </script>

    </head>

    <body onload='setImag e()' onunload='GUnlo ad()'>

    [/code]
    ok so there is the code... however the function in the onunload position wont work whenever i have onload in the body tag with it... can anyone explain to me why this is so? and maybe if you could help me with a work around would be great i tried throwing the onload in a frameset tag and an image tag and.. well the image tag worked kind of but i read in some places that onload in an image tag is not reliable.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, banning. Welcome to TSDN!

    Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

    Changed thread title to better describe the problem (did you know that threads whose titles contain phrases such as, 'I need help' actually get FEWER responses?).

    Comment

    • banning
      New Member
      • Aug 2007
      • 42

      #3
      Originally posted by pbmods
      Heya, banning. Welcome to TSDN!

      Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

      Changed thread title to better describe the problem (did you know that threads whose titles contain phrases such as, 'I need help' actually get FEWER responses?).

      code tags? sorry i didnt read the thing i just needed help real quick this is my first time ever posting on a forum.. i can usually find what ineed just reading other ppls questions

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, banning.

        We're glad you're here, and I hope you find the help you are looking for.

        Please follow the posting guidelines when posting to this site. Thanks!

        Comment

        • banning
          New Member
          • Aug 2007
          • 42

          #5
          is my post ok the way it is right now? or am i still missing some guidlines? or where you just letting me know for future reference?

          Comment

          • johnhjohn
            New Member
            • Dec 2006
            • 43

            #6
            The reason why the onunload event is not firing might be because there is an error in your function GUnload() or another function within the same script tag. For example:

            [CODE=javascript]
            <html>
            <head>
            <script language="javas cript" type="text/javascript">

            function unload()
            {
            alert("Page is unloading);
            }

            </script>
            </head>
            <body onunload="unloa d()">

            </body>
            </html>
            [/CODE]

            The function unload() will not work and there are no errors on the page.

            Comment

            • banning
              New Member
              • Aug 2007
              • 42

              #7
              Originally posted by johnhjohn
              The reason why the onunload event is not firing might be because there is an error in your function GUnload() or another function within the same script tag. For example:

              [CODE=javascript]
              <html>
              <head>
              <script language="javas cript" type="text/javascript">

              function unload()
              {
              alert("Page is unloading);
              }

              </script>
              </head>
              <body onunload="unloa d()">

              </body>
              </html>
              [/CODE]

              The function unload() will not work and there are no errors on the page.
              the onunload function i have no control over... its as function, through google, that loads google maps on my page.

              One thing though that onunload fires off just fine when i dont have the onload going off with it. however the onload shouldnt effect it should it? i mean in theory onunload should still fire off even if i use the onload right?

              another thing i may want to say is when i run each of the function independently they work just fine, its when i want them to both be in the body tag at the same time that the onunload throws a fit and wont load google maps.

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #8
                Heya, banning.

                onunload fires when the User *leaves* the page.

                Comment

                • banning
                  New Member
                  • Aug 2007
                  • 42

                  #9
                  Originally posted by pbmods
                  Heya, banning.

                  onunload fires when the User *leaves* the page.



                  if you want to take a look at the source code it uses onunload to load the google maps down on the page... if you switch it to onload then it wont load the google maps... so it has to be onunload because of something that happens on googles end id guess, but i dont know. Either way onunload is staying because it has to, now why it wont play friendly with the onload is beyond me... please help meh out lol i dont get it.

                  and if you guys cant figure it out either its all good because i found another work around to get the result i wanted "more than one way to skin a cat" i always say.

                  so now im just curious why the onunload wouldnt fire when i would add the onload next to it.

                  Comment

                  Working...