Solved

Behaviour of window.focus() with IE8

Posted on 2009-07-09
2
1,935 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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now