Solved

JavaScript multiple window.open gradually crashes IE7

Posted on 2007-11-22
7
748 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
This article discusses how to create an extensible mechanism for linked drop downs.
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
Suggested Courses

623 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