Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

yellow

Moderator emeritus
Original poster
Oct 21, 2003
16,018
6
Portland, OR
I have a form to submit a trouble ticket via the web, it takes a bit for the form to process after the "submit" button is hit. Consequently there's people who click,click,click,click away at it and we get n submissions of the same ticket.

So I'm trying to use a window to appear to stop that from happening while the form processes in the background. At the end of the javascript that passes the gathered info to the form for processing, I call the function below.

New window ("stop clicking submit, dumbs***") opens, takes focus, and should disappear of it's own accord in 8 seconds.

Using the following code:

Code:
function openWin()
{
myWindow=window.open('http://domain.com/blah','','width=800,height=600');
myWindow.setTimeout('close();',8000);
myWindow.focus();
}

Well, this works like a charm in IE7, IE8, FF3.x in Mac & Win, but not in Safari. The window never closes.

I've tried using the debugger in Safari to figure out the problem and reading the dev documentation on the apple dev site, but I'm not coming up with any answers. I'd prefer to get the correct javascript into the main page where all this is defined and called from, and not put a separate close() in the HTML of the opened window. That just seems sloppy, and lord knows, it's sloppy enough as it is.

Thanks for any help/advice.
 
I too have tried it in Firefox, IE8, and Safari, but for me it doesn't work in any of them. The window opens (if you turn off the pop-up blocker) but it never closes.

Wish I could help.
 
Code:
window.close();
or you may need,
Code:
myWindow.setTimeout(function(){window.close();}, 8000);
 
Yeah, I've tried those variations too and they won't work either.

Works in everything except Safari.
Code:
function openWin()
{
	myWindow=window.open('http://domain.com/blah','','width=775,height=500');
	myWindow.setTimeout('window.close();',4000);
	myWindow.focus();

}

And this doesn't work in anything.
Code:
function openWin()
{
	myWindow=window.open('http://domain.com/blah,'','width=775,height=500');
	myWindow.setTimeout(function(){window.close();},4000);
	myWindow.focus();

}

I've also tried (found here):

Code:
function openWin()
{
        myWindow=window.open('http://domain.com/blah,'','width=775,height=500');
	setTimeout(toodle, 4000)
	function toodle() 
        {
		if (myWindow != '' &&
		!myWindow.closed &&
		myWindow.name !== undefined) 
        {
			myWindow.close();
	}
     }
}

EDIT:

Even stranger, this does work (a test set from w3schools):
Code:
<html>
<head>
<script type="text/javascript">
function openWin()
{
myWindow=window.open('','','width=200,height=100');
myWindow.document.write("This is 'myWindow'");
myWindow.focus();
myWindow.setTimeout('window.close();',2000);
}
</script>
</head>
<body>

<input type="button" value="Open 'myWindow'" onclick="openWin()" />

</body>
</html>

:confused:

So I tried this as a test (works in FF/win):
Code:
function openWin()
{
	myWindow=window.open('','','width=775,height=500');
         myWindow.document.write("Stop clicking Submit please");
	myWindow.focus();
         myWindow.setTimeout('window.close();',4000);
}

In Safari, opens window, no text, closes window in 4000ms. <ELBOW>
 
Actually, let's make this simpler and address the problem you're trying to resolve, multiple submits.

form with onsubmit="OurFuntion();"
and input type="submit" id="submit" />

PHP:
function OurFunction() {
  // Disable submit button now that it has been pushed
  document.getElementById('submit').disabled = true;
  // do other stuff
}
 
Thanks, that didn't work for me either, but I don't have access to the form declaration (don't ask).
So, I just opted for the ugly way and put an "onload" in the pop-up window that closes after 8.5 seconds.

Thanks for all your help though!!
 
The company as a whole has a web dev team, they create "templates" so the look and feel of company pages is the same across the board and provide us with "edit" right through some craptacular editor. And editor that strips out all backslashes, which makes it difficult to add a newline into javascript to output info on different lines of their form. I have to add a \ to a variable every time I edit this. This crap is so old they're still using <h1> and <strong>. :eek:
 
Using <h1></h1> is good for SEO purposes as search engines look for it to get a context for the page in question which presumably offers more information than the page title which is often site or section wide.
 
Except that these are all intranet junk that no search engines ever hit. Their "editor" loves to add empty divs all over the place.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.