Solved

Behaviour of window.focus() with IE8

Posted on 2009-07-09
2
1,944 Views
Last Modified: 2013-11-19

I am trying to simulate the functionality of modal dialog windows using javascript..

I would do this by invoking the window.focus method of the dialog window whenever the parent window gets focus.

This has worked fine with IE6 and with IE7 ; but with IE 8 - it works well on some workstations; however on other workstations all that happens is that the taskbar button for the dialog window flashes when window.focus() is invoked.. (the dialog window is not brought up to the front)


I open the dialog window like this:

dialogWin =window.open('aform.aspx','aaa', attr);

...

I handle the onfocus event of the opener window like this:

if (dialogWin != null && !dialogWin.closed)
{
            dialogWin.focus();
}


This has worked well with past versions of IE; however it does not work with IE 8 on some workstations (the button on the taskbar merely flashes)

Is there any other approach I can take?   I realize I can use showModalDialog; but this would involve rewriting a lot of code.



Thanks

0
Comment
Question by:atomic500
2 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 24820840
Why would it involve a rewrite?

If you really want to, you can do

if (window.showModalDialog) window.open=new function(url,target,parms) {
  var ret = showModalDialog(url,window,parms.replace(',',';').replace('width','dialogWidth').replace('height','dialogHeight'); // add whatever you need
  return ret
}


so only where you need to manipulate the window afterwards do you need to change stuff and you can do a change of
opener.
to
if (window.dialogArguments) opener=window.dialogArguments

However a better choice is to use something like lightbox 2 or thickbox or greybox since it does not involve opening new windows which is blocked on many PCs
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question