1

I am trying to create an HTML file that when run, will open a URL in a new tab (the URL is pointing to a file on a local server, so when the HTML is run it in fact prompts the user to open or save the file), and then after x seconds, closes itself without the prompt asking the user if they wish to close the tab.

Only Internet Explorer can be used, as my company does not allow other browsers.

I already have a file that opens and closes the tab, however, the tab is closed almost immediately, which does not allow time for the prompt to come on-screen and ask the user if they wish to open or save the file. Here is my code so far:

<html>
<head>
<title>You are being redirected</title>
<meta HTTP-EQUIV="REFRESH" content ="0; url=X:\\Directory\Subdirectory\File.docx">
</head>
<body>
<center>
<script type="text/javascript">
 window.open('javascript:window.open("", "_self", "");window.close();', '_self');
</script>
</center>
</body>
</html>

A solution to my problem would be to just literally add a delay between the tab opening and closing in the above code (ideally 5 seconds or 5000 milliseconds). If anyone could show me how to add this delay before it closes that would be extremely helpful.

jbduzan
1,1262 gold badges14 silver badges30 bronze badges
asked Jul 13, 2015 at 8:20
3

3 Answers 3

3
<script type="text/javascript">
setTimeout(function() {
 window.open('javascript:window.open("", "_self", "");window.close();', '_self');
}, 5000);
</script>
answered Jul 13, 2015 at 8:46
Sign up to request clarification or add additional context in comments.

2 Comments

This did exactly what I wanted. Thanks for the fast reply!
No problem Varx! Glad I could help :)
1

You should use settimeout():

setTimeout(function,milliseconds,param1,param2,...)

Read about it here: w3schools settimeout();

answered Jul 13, 2015 at 8:42

Comments

1

This works to open a new tab and close it after 5 seconds

 var wnd = window.open("http://google.com", "_blank", "");
 window.setTimeout(closeWindow, 5000);
 function closeWindow() {
 wnd.close();
 }
answered Jul 13, 2015 at 8:57

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.