Seeking help using window.open and window.close, Seeking help using window.open and window.close |
Seeking help using window.open and window.close, Seeking help using window.open and window.close |
PeterR |
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! |
Brian Chandler |
Aug 4 2024, 04:39 AM
Post
#2
|
Jocular coder Group: Members Posts: 2,480 Joined: 31-August 06 Member No.: 43 |
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. |
Lo-Fi Version | Time is now: 6th December 2024 - 08:29 AM |