By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,453 Members | 937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,453 IT Pros & Developers. It's quick & easy.

Global event handler of new window being lost on location change

P: n/a
I am modifying existing code to add modal functionality to an IE5+
ActiveX Web-App. What I am trying to achieve is simple modal behaviour
on popup windows, apart from certain specified ones. I initially
attempted to use a direct assignment to the onblur handler of the new
window, but for some reason couldn't get it to work, so I've instead
used attachEvent. This provides simple modal functionality.

The problem that I need help with is that for some reason the attached
event handlers die when the page is reloaded or goes to another page.
I'm a little surprised as I would expect the global window event handler
to carry across reloads or location changes, and that's why I'm asking
for your help!

<script type="text/javascript">

var wOpen = null;

function DoNewWindow( sUrl, sTitle, sStyle, iWidth, iHeight )
{
wOpen = window.open(sUrl,sTitle,sStyle);
var bIsModal = true;
switch ( sTitle )
{
case 'Help' :
case 'UserAdmin' :
case 'Account' :
bIsModal = false;
break;
default :
break;
}
if ( bIsModal )
{
wOpen.attachEvent( 'onload', wOpen.focus );
wOpen.attachEvent( 'onblur', wOpen.focus );
}
}

</script>

Fred Basset
fr*********@whosyourdaddy.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Fred Basset <fr*********@whosyourdaddy.com> writes:
The problem that I need help with is that for some reason the attached
event handlers die when the page is reloaded or goes to another page.
I'm a little surprised as I would expect the global window event handler
to carry across reloads or location changes,
It doesn't. The window object is reinitialized when a new page is loaded
into it.
and that's why I'm asking for your help!


With what?

You will have to assign the handler again on each page.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
Sorry, I should have made myself more clear in my question. How can I
(if it's possible) carry across the modal functionality between the
window objects? I'd like to be able to setup all the necessary event
handling with the initial window-launch function, rather than having to
resort to hard-coding things into the actual pages of the popup window.

All I can come up with is the general idea that the onBeforeunload event
could capture the loss of the page, but I'm not sure how to set the new
event handlers ... if I set an onblur on the window with the
onbeforeunload then the event handling will be lost when the new page
comes in :/

Any suggestions or ideas would be gratefully received.

Fred Basset
fr*********@whosyourdaddy.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3

P: n/a
On 05 Sep 2003 21:12:24 GMT, Fred Basset
<fr*********@whosyourdaddy.com> wrote:
All I can come up with is the general idea that the onBeforeunload event
could capture the loss of the page, but I'm not sure how to set the new
event handlers ... if I set an onblur on the window with the
onbeforeunload then the event handling will be lost when the new page
comes in :/


Modify the windows properties to be modal using win32 API, or use a
modelessDialog, or use Zeepe http://www.zeepe.com/ rather than
hackish javascript solutions, when you're not in a default security
environment.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #4

P: n/a
I'm doing it centrally to cut down on development time. To convert all
the windows to proper IE modal dialogues is not a possibility.

If I can't do it in Javascript then I will have to set the onblur in
every individual popup page ... something I am not keen on doing. I do
realise that in an ideal world "hackish javascript solutions" are not to
be recommended, but I'm working on an antiquated GUI which could
possibly (hopefully) be replaced soon from scratch anyway ... there's no
point wasting valuable time if I can help it, hence the desire for a
pure javascript solution.

Fred Basset
fr*********@whosyourdaddy.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5

P: n/a
On 05 Sep 2003 22:42:28 GMT, Fred Basset
<fr*********@whosyourdaddy.com> wrote:
I'm doing it centrally to cut down on development time. To convert all
the windows to proper IE modal dialogues is not a possibility.

If I can't do it in Javascript then I will have to set the onblur in
every individual popup page ... something I am not keen on doing.


You do realise that the onblur "solution" doesn't even work reliably,
so I'm not sure what you're doing.

In a non-secure environment you can do it, using win32 API calls, (you
find the window, change the properties and make it modal, your app can
do this.) if that's too much learning from where you are now, then
there's the zeepe option which can do it easily, although that would
be a cost option.

Also, you could modify all IE's such that window.open was a call to a
modeless dialog, that gives you modeless dialog behaviour, without
having to change any behaviour other than capturing IE events.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #6

P: n/a
DU
Fred Basset wrote:
I'm doing it centrally to cut down on development time. To convert all
the windows to proper IE modal dialogues is not a possibility.

Resorting to showModelessDialog() should achieve your goals better than
an onblur attachEvent code which might not work well anyway.
If I can't do it in Javascript then I will have to set the onblur in
every individual popup page ... something I am not keen on doing.
This does not sound right to me. showModelessDialog() (or even
showModalDialog()) are reasonable straightforward javascript solutions
meeting your requirements.

I do realise that in an ideal world "hackish javascript solutions" are not to
be recommended, but I'm working on an antiquated GUI which could
possibly (hopefully) be replaced soon from scratch anyway ... there's no
point wasting valuable time if I can help it, hence the desire for a
pure javascript solution.


IMO, you're not saving time with onblur, onload attachEvent code ...

My 2 cents..

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

Jul 20 '05 #7

P: n/a
Thank you for your help guys ... I have indeed managed to use
showModalDialog. My hesitation arose from an ignorance about how it is
implemented ... I was worried about the fact that some of the popups are
required to be modal, but not all, but I have worked around the code. I
do however now have a new problem! :D

Some of the popups have 'tabs' which actually link to separate pages,
however clicking on the links pops up new browser windows pointing to
the login page rather than changing the location of the modal dialog ...
is this the only behaviour possible within a modal dialog, or can the
location be changed?

Fred Basset
fr*********@whosyourdaddy.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #8

P: n/a
I need your help again, if possible.

I have decided to put an iframe (width,height 100%) inside the
modalDialog and then display the existing pages inside that. This
appears to work quite well, however when you resize the dialog (by any
amount), a border appears on the right hand side of the dialog box (in
the color of the background of the dialog itself), of about the width of
a scrollbar. I'm not quite sure what to do about this.

It appears to be peculiar to modalDialogs ... I've replaced the
showModal with window.open and the same problem does not occur. It only
occurs on resize, but I can think of nothing to solve it using the
iframe's onresize event handler, even though it definitely fires.

Anyone have any suggestions?

Fred Basset
fr*********@whosyourdaddy.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.