View Full Version : Force browser to close and reopen.

03-20-2012, 08:58 AM
Hi, I am new here, it's nice to meet you guys.

I am writting a javascript that need to force the user to close the current browser and then restart automatically again after some operation. Here is the case :

The user will retrieve a file from the server and save it in the local drive. After that, the browser will automatically open the .pdf saved with the browser(IE) but not Adode reader.

If the user wants to update the previous saved .pdf in the local drive, they will need the user to close the opened file(saved .pdf) so that new updated .pdf can be replaced to the old .pdf file. So, I need to implement a function that force the browser to close, then copy and replace the old file, then reopen the file(new and updated) again.

Is there any possible way of doing this ? Please provide me some idea. I have tried to look for informations online but I just got no luck. Failed with the coding provided. Thanks in advance.

P/S : The file need to be closed in order to replace it with a new one. The platform using is Windows.

03-20-2012, 10:04 AM
You can't force someone to do anything with JavaScript - they have complete control and can turn off JavaScript completely, turn it off selectively for your page, or simply add their own script to the browser that overrides yours.

In any case JavaScript is only able to close a browser window that was opened using JavaScript and where the original page is still displayed there.

Also when using window.open in JavaScript you still have no control over whether it opens in a new window, a new tab, or simply overwrites the current page - as that too can be selected by the person who owns the browser.

From your PS it sounds like you simply want to do a forced reload of the current page in which case you just need location.reload(true); (the true forces it to reload from the server - with false it would reload from the browser cache).