Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    52
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Force browser to close and reopen.

    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.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,625
    Thanks
    0
    Thanked 645 Times in 635 Posts
    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).
    Last edited by felgall; 03-20-2012 at 09:06 AM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •