Solved

JavaScript multiple window.open gradually crashes IE7

Posted on 2007-11-22
7
741 Views
Last Modified: 2013-12-08
My site has a page containing multiple JavaScript scripts to open sub-windows. There is no problem with Firefox or with IE6, but in IE7 I find that any one new window will open properly, and sometimes more than one will; but eventually, after opening and closing windows, I get a blank white one at best. If I close that one and try another, only the border of the window appears. If I then try refreshing the main window, I find it nearly frozen.

I've tried resetting plugins in IE7 and turning off the phishing-detection feature, with no success. I've also searched the Internet for solutions but couldn't any mention of this particular problem. Since it's IE7-specific, and IE is usually less strict than Firefox, I suspect the problem is not with my code. However, I'll attach a sample of the scripts in the head of my document and the links in the body.

Thanks for any help.
<head>

<script language="JavaScript">

function test01()

{

test01open = window.open("../tests/test01.php","test01open"

,"location=0,scrollbars=0,menubar=0,toolbar=0,status=0,resizable=0,directories=0,left=180,top=60,width=580,height=480");

test01open.moveTo(180,60);

}

</script>

</head>
 

<body>

<a href="javascript:void(0)" onClick="test01();return false" onMouseOver="javascript: window.status=''; return true;"onmouseout="javascript: window.status=''; return true;">To take the test, click here</a>

</body>

Open in new window

0
Comment
Question by:debitto
  • 4
  • 3
7 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 250 total points
ID: 20337786
Apart from this link looking weird

<a href="javascript:void(0)" onClick="test01();return false" onMouseOver=onmouseout"javascript: window.status=''; return true;"="javascript: window.status=''; return true;">To take the test, click here</a>

I would think

<a href="#"
onClick="test01();return false"
onMouseOver="window.status='Something'; return true"
onMouseOut="window.status=''; return true;">To take the test, click here</a>

it looks ok...

You could try this:

var myWindows = new Array();
function testOpen(url,target) {
  myWindows[target]=window.open(url,target,
  "left=180,top=60,width=580,height=480");
  if (myWindows[target]) {
    myWindows[target].moveTo(180,60);
    return false; // cancel the href
  }
  return true; // use the href itself
}

and have
<a href="../tests/test01.php" target="test01"
onClick="return testOpen(this.href,this.target)">To take the test, click here</a>


which should be safer and reusable and should be able to handle popup blockers

My guess is you have some plugin that makes IE sick, but I will be interested in hearing about possible bugs.
0
 

Author Comment

by:debitto
ID: 20337866
Thanks for your reply. Before trying out what you've suggested, I'll confirm that the link is messed up in my original snippet. Don't know why, since I pasted it in.  What I really have is pretty much what you imagined, except that window.status is empty for onMouseOver:

<a href="javascript:void(0)" onClick="test01();return false" onMouseOver="javascript: window.status=''; return true;"onmouseout="javascript: window.status=''; return true;">To take the test, click here</a>

Hope it didn't get garbled again. I'll also add that the trouble occurs when rapidly opening and closing popups (which doesn't faze IE6 or Firefox 2). I've done it more slowly without trouble, but haven't tested exhaustively. Maybe it's just MS bloat. I've reset plugins a couple of times without seeing any benefit.

By the way, congratulations on your Expert Points. You're contributing a lot of help, I see.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20337928
:) Thanks
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Closing Comment

by:debitto
ID: 31410628
Great! Your code works beautifully as-is for a single link, and now that I've made modified copies for my other links, I have not only a solution to my problem but other benefits as well. I'll summarize my understanding of it and my modifications for other people's reference. Please correct me where I go wrong.

1) As long as I don't mind having all popups open in the same place and with the same dimensions, I need only one instance of the code that defines the variable myWindows and creates the function testOpen (inside a script tag, of course). Since I do need other sizes of popup, I've made copies of the function (testOpen01, testOpen02, etc.) with appropriate width and height values.

2) The links must have unique target values, which can be anything, besides pointing to different files. With testOpen modified as testOpen01, etc., everything works. I've done enough testing with IE7 to convince me the problem is gone. My old scripts have become entirely unnecessary; in other words, the resemblance between your target="test01" and my function test01() is coincidental.

Besides working, your code will indeed be convenient to reuse. What exactly did you mean about its being safer?

I'm increasing the points for this, not only because it would have been very difficult for me to arrive at the solution on my own -- and, believe me, I do quite a bit of studying when my real job permits -- but also because it will improve the quality and efficiency of my coding hereafter.

Many thanks.
0
 

Author Comment

by:debitto
ID: 20338434
I added this comment when accepting the solution, but that must have been for your eyes only. Here it is for general reference.

Great! Your code works beautifully as-is for a single link, and now that I've made modified copies for my other links, I have not only a solution to my problem but other benefits as well. I'll summarize my understanding of it and my modifications for other people's reference. Please correct me where I go wrong.

1) As long as I don't mind having all popups open in the same place and with the same dimensions, I need only one instance of the code that defines the variable myWindows and creates the function testOpen (inside a script tag, of course). Since I do need other sizes of popup, I've made copies of the function (testOpen01, testOpen02, etc.) with appropriate width and height values.

2) The links must have unique target values, which can be anything, besides pointing to different files. With testOpen modified as testOpen01, etc., everything works. I've done enough testing with IE7 to convince me the problem is gone. My old scripts have become entirely unnecessary; in other words, the resemblance between your target="test01" and my function test01() is coincidental.

Besides working, your code will indeed be convenient to reuse. What exactly did you mean about its being safer?

I'm increasing the points for this, not only because it would have been very difficult for me to arrive at the solution on my own -- and, believe me, I do quite a bit of studying when my real job permits -- but also because it will improve the quality and efficiency of my coding hereafter.

Many thanks.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20339573
Thanks - however I would not copy the code just because it needs different dimensions
I would pass the dimensions as parameters


The script can handle a popup blocker by allowing the href to work in case the window.open did not

I removed the moveTo since you have top and left anyway

// create a global var in case you want to close all windows from one place
var myWindows = new Array();
 
// pass the url (mandatory), target (optional), width and height - top and left (optional)
function testOpen(url,target,width,height,top,left) {
  target = (target)?target:"_blank"; // if no target passed, default to blank
  width = (width)?width:"580";
  height = (height)?height:"480";
  top = (top)?top:"60";
  left = (left)?left:"180";
  myWindows[target]=window.open(url,target,
  "left="+left+
  ",top="+top+
  ",width="+width+
  ",height="+height);
  if (myWindows[target]) {
    return false; // cancel the href
  }
  return true; // use the href itself
}
 
and have
<a href="../tests/test01.php" target="test01"
onClick="return testOpen(this.href,this.target)">To take the test, click here</a>
<a href="../tests/test02.php" target="test02"
onClick="return testOpen(this.href,this.target,600,800,0,0)">To take the test, click here</a>

<a href="../tests/test03.php"
onClick="return testOpen(this.href)">All default here</a>
0
 

Author Comment

by:debitto
ID: 20341236
Thanks for adding so much help in open discussion. This will save me a lot of trouble and space. I also understand the element of safety as safety from cross-site scripting attack, in view of the way the target is passed to window.open.

Best wishes.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Joomla Website Malfunction 9 53
Angular JS question 24 39
dynamics crm 2011 - Web Resources 1 26
web browser 3 24
Internet is a big network which is formed by connecting multiple small networks.It is a platform for all the users which are connected to it.Internet act as platform in different fields. Such as: Internet  as a collaboration platform. Internet  as…
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

760 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

18 Experts available now in Live!

Get 1:1 Help Now