The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Seeking help using window.open and window.close, Seeking help using window.open and window.close
PeterR
post Jul 18 2024, 04:04 PM
Post #1





Group: Members
Posts: 4
Joined: 15-March 23
Member No.: 28,855



My index.html script below has a problem.

<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<script>
function redirectFunc() {
window.open("https://www.google.com");
}
setTimeout("redirectFunc()", 8000);
//window.close();
</script>
</body>
</html>

Currently it loads google.com url after 8 seconds
but my desire is to load google.com for a period
of 8 seconds, then close the google browser tab.
I don't see where my mistake is in above code!?
Help resolving this would be greatly appreciated!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Aug 4 2024, 04:39 AM
Post #2


Jocular coder
********

Group: Members
Posts: 2,480
Joined: 31-August 06
Member No.: 43



QUOTE(PeterR @ Jul 19 2024, 06:04 AM) *

My index.html script below has a problem.

<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<script>
function redirectFunc() {
window.open("https://www.google.com");
}
setTimeout("redirectFunc()", 8000);
//window.close();
</script>
</body>
</html>

Currently it loads google.com url after 8 seconds
but my desire is to load google.com for a period
of 8 seconds, then close the google browser tab.
I don't see where my mistake is in above code!?
Help resolving this would be greatly appreciated!


I'm only guessing, but perhaps setTimeout(x, 8000) means "Do x after 8 seconds". Since x is "open a google window" this indeed happens after 8 seconds. Then you have commented out "close the window". I think you meant to set the timer for "close the window", and then call your redirect function (not commented out). No obvious point in not directly writing the window.open() function though. And you should not be able to close the window without at least a confirmation from the user.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
3 User(s) are reading this topic (3 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 2nd December 2024 - 09:31 PM