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 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    52
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Check if the html url is opened in the tab/window

    Here is my scenario, i have a html that allows the user to retrieve .pdf file from the server.

    If the users are trying to open the html again, mean the user open a new tab/window to the same html url, the window will prompt the user that the html is already opened.

    The user will need to close the old html tab/window first before open a new one.

    Is it possible to stop the users to open the new same html file before he/she closes the old one ? Is there any link that teach the tutorial about this ?

    I am wondering do i need to use cookies in the browser to store the url in order to compare to the new tab/window url ?

    Thanks for helping. I appreciate this a lot.
    Last edited by Jian0203; 05-17-2012 at 02:19 AM.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,465
    Thanks
    0
    Thanked 634 Times in 624 Posts
    If you do manage to do something using a cookie then it would still be able to be bypassed simply by using a different browser.
    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.

  • #3
    New Coder
    Join Date
    Mar 2012
    Posts
    52
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    If you do manage to do something using a cookie then it would still be able to be bypassed simply by using a different browser.
    Er... Do you mind to explain a little about this ? I don't really understand ~ Sorry for troubling you ~~

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    There's an easy fix for this that should do what you want, or at least give the same effect.

    Code:
    <a href="someFile.pdf" target="MYPDF"> click to open </a>
    Now, even if the user DOES click again, the PDF file will open in the *SAME* window (or tab)! That is, by specifying the target, you are telling the browser to re-use that window, NOT open another one.

    If you are opening the PDF window via JavaScript, again just give the window name:
    Code:
    window.open("someFile.pdf","MYPDF","width=900,height=700");
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New Coder
    Join Date
    Mar 2012
    Posts
    52
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    There's an easy fix for this that should do what you want, or at least give the same effect.

    Code:
    <a href="someFile.pdf" target="MYPDF"> click to open </a>
    Now, even if the user DOES click again, the PDF file will open in the *SAME* window (or tab)! That is, by specifying the target, you are telling the browser to re-use that window, NOT open another one.

    If you are opening the PDF window via JavaScript, again just give the window name:
    Code:
    window.open("someFile.pdf","MYPDF","width=900,height=700");

    but I have my concern. Because the pdf opened CAN only be closed after the machine has finished a process, but some users just don't follow the instructions.

    they will still open another tab/windows to run the html to view another pdf that might cause confusion to other users whether which one is the correct reference pdf.

    So, I want to restrict the users to open the html in new tab/window before he/she closes the old html.

    Is it possible to do so ? Thanks for helping

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Did you try my answer?

    Try it first, then see if it really has problems.

    I don't see how cookies could help you. How will a cookie know whether or not the prior tab/window has been closed???
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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