onunload without body tag reference?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Vallelunga

    onunload without body tag reference?

    I'm working on an asp.net site and am trying to implement a popup help
    window. I want the window to close when the user advances to the next page
    in our application. The thing is, I'm doing this on a component basis and I
    don't have access to the body tag from within my help component, so I can't
    add the onunload tag. Is there some other way of achieving what I want? Can
    I add an eventhandler to the body tag through javascript?

    Thanks,

    Brian


  • Grant Wagner

    #2
    Re: onunload without body tag reference?

    Brian Vallelunga wrote:
    [color=blue]
    > I'm working on an asp.net site and am trying to implement a popup help
    > window. I want the window to close when the user advances to the next page
    > in our application. The thing is, I'm doing this on a component basis and I
    > don't have access to the body tag from within my help component, so I can't
    > add the onunload tag. Is there some other way of achieving what I want? Can
    > I add an eventhandler to the body tag through javascript?
    >
    > Thanks,
    >
    > Brian[/color]

    <script type="text/javascript">
    function myUnloadHandler () {
    // do something
    }
    window.onunload = myUnloadHandler ;
    </script>

    The problem of course is that when the unload event fires, I'm not sure if the
    function is still in scope on the page. What you may need to do is put the
    unload event handler function in the opener, then invoke it from the popup:

    <script type="text/javascript">
    function popupUnloadHand ler() {
    if (window.opener && window.opener.u nloadHandler) {
    window.opener.u nloadHandler();
    }
    }
    window.onunload = popupUnloadHand ler;
    </script>

    --
    | Grant Wagner <gwagner@agrico reunited.com>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *


    * Internet Explorer DOM Reference available at:
    *
    Gain technical skills through documentation and training, earn certifications and connect with the community


    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
    * http://www.mozilla.org/docs/web-deve...upgrade_2.html


    Comment

    • Brian Vallelunga

      #3
      Re: onunload without body tag reference?

      Thanks for the suggestions. I actually found a way to do this with asp.net.
      Essentially, I am able to call a script from onsubmit. So all I do is define
      a script, and then register it with the RegisterOnSubmi tStatement() method.
      Thanks for the help though.

      Brian

      "Grant Wagner" <gwagner@agrico reunited.com> wrote in message
      news:3F2563CB.B D35200D@agricor eunited.com...[color=blue]
      > <script type="text/javascript">
      > function myUnloadHandler () {
      > // do something
      > }
      > window.onunload = myUnloadHandler ;
      > </script>
      >
      > The problem of course is that when the unload event fires, I'm not sure if[/color]
      the[color=blue]
      > function is still in scope on the page. What you may need to do is put the
      > unload event handler function in the opener, then invoke it from the[/color]
      popup:[color=blue]
      >
      > <script type="text/javascript">
      > function popupUnloadHand ler() {
      > if (window.opener && window.opener.u nloadHandler) {
      > window.opener.u nloadHandler();
      > }
      > }
      > window.onunload = popupUnloadHand ler;
      > </script>
      >
      > --
      > | Grant Wagner <gwagner@agrico reunited.com>
      >
      > * Client-side Javascript and Netscape 4 DOM Reference available at:
      > *
      >[/color]
      http://devedge.netscape.com/library/...ce/frames.html[color=blue]
      >
      > * Internet Explorer DOM Reference available at:
      > *
      >[/color]
      http://msdn.microsoft.com/workshop/a...ence_entry.asp[color=blue]
      >
      > * Netscape 6/7 DOM Reference available at:
      > * http://www.mozilla.org/docs/dom/domref/
      > * Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
      > * http://www.mozilla.org/docs/web-deve...upgrade_2.html
      >
      >[/color]


      Comment

      Working...