473,804 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 20 '05 #1
2 7730
Brian Vallelunga wrote:
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


<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 <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* 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
Jul 20 '05 #2
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" <gw*****@agrico reunited.com> wrote in message
news:3F******** *******@agricor eunited.com...
<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 <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp
* 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

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
15912
by: kaeli | last post by:
Hey guys, This error occurs ONLY in Netscape 7.0. Not in 7.1. So, I think it's a bug. Buuuut... Has anyone had this problem or know of a fix? When attempting to have an onunload function set with "window.onload=", the error comes up "permission denied to set property window.onunload"
2
1654
by: Rich | last post by:
Is there any way to get the same effect that the body tag onUnload creates. I need a script that will be placed in the body of the html that will open a new window when the parent is closed. The window that will open is a survey for a webcast they just viewed. I can't put the script in the header or place a onUnload command in the body tag. Only place I can put it is in the body of the page within a script file. Thanks a bunch!
2
1206
by: Oleg Ogurok | last post by:
Hi all, Is there a way to add a client side onunload statement into the <body> tag of a page? Thanks. -Oleg.
3
2263
by: Weston Weems | last post by:
Ok, I've posted on this before, lemme give you guys the run down. I've got an asp form that has postbacks etc. I'd like it so that when navigating away from it, It'll prompt user for save confirmation. So I've got <body onUnLoad="CheckConfirm();"> The javascript method fires off, and I've got no question
1
5328
by: Laurent Bugnion | last post by:
Hi, I am trying to programatically add an "onunload" event handler to the "body" tag of an ASPX page. I am doing this from a Custom Control located on this page. To do this, I added "runat=server" to the body tag, which provides me access to it in the code-behind through a HtmlControl. I can then manipulate the Attributes collection, which is what I needed. So far so good.
1
3241
by: Kourosh | last post by:
I'm using IE6 and I've just created a simple page with this event: <body onunload="alert('sad')"> could someone tell me if this works for you if you have IE 6? I've tested this in firefox and IE 7 and they both work fine with it. but on the IE6 copy I'm testing, the event is fired only when the page is refreshed. It's not fired when I close the page.
1
1528
by: Tim Arview | last post by:
Hi, I'm trying to create an exit popup that doesn't require anything added to the body tag. In other words, I don't want to say <body onunload="foo">. I just want to have window.onunload="foo" in the <scripttag. However, when I do that, it launches foo as soon as the page loads and does NOT launch when the page is unloaded.
5
18009
by: ~~~ .NET Ed ~~~ | last post by:
Well the subject says it all but I am going to elaborate a bit. As we all now since 2.0 it is possible to access the Header from code behind without much wizardry and that is a good thing. Now, in my site I am using master pages and one of the site pages (but could be more) needs certain customization in which the BODY tag needs the onLoad and onUnload events added to it:
0
9593
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7633
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.