Global event handler of new window being lost on location change

F

Fred Basset

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
(e-mail address removed)
 
L

Lasse Reichstein Nielsen

Fred Basset said:
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
 
F

Fred Basset

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
(e-mail address removed)
 
J

Jim Ley

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.
 
F

Fred Basset

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
(e-mail address removed)
 
J

Jim Ley

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.
 
D

DU

Fred said:
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/doctorunclear/Netscape7/Netscape7Section.html
 
F

Fred Basset

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
(e-mail address removed)
 
F

Fred Basset

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
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top