Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 752
  • Last Modified:

JavaScript multiple window.open gradually crashes IE7

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
debitto
Asked:
debitto
  • 4
  • 3
1 Solution
 
Michel PlungjanIT ExpertCommented:
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
 
debittoAuthor Commented:
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
 
Michel PlungjanIT ExpertCommented:
:) Thanks
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
debittoAuthor Commented:
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
 
debittoAuthor Commented:
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
 
Michel PlungjanIT ExpertCommented:
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
 
debittoAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now