SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Preventing an HTML page save/download

    Hello,

    Is there anyway to prevent people from downloading an HTML document from my website using JavaScript?
    For example, My page is located at: "http://mysite.com/dir/page.html", how can I (using JavaScript or client-side codes) prevent someone from downloading that page (by right clicking the link > Save Target As...)?

    P.S. I have to do this using JS or some other client-side language as this is on a free host that only allows HTML, so NO PHP, ASP, .htaccess,...

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    You can't stop someone from getting your source code. The best you can do is block right click but as with anything javascript you just have to turn it off and it's defeated. It also won't stop someone from saving the page through the file menu. If you don't want people to have it, just don't put it on the web.

  3. #3
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To view a page it has to be downloaded first. So regardless of whether or not the person knows it they have a copy on their computer already just by visiting the page.

    This is asked very often. The answer is simple: if don't want people to access/download it, don't put it on the web. Alternatively, login forms can be used to control access, but since you don't have access to a server-side language or .htaccess, you're out of luck.

    Edit: stymiee beat me to it. I'll leave my reply anyway.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  4. #4
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no matter how you protect it, you can block regular users who use IE to save by right clicking. But you can't be fully protected from advance users

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The browser has already saved a copy of all the content before it displays the page. Even encrypted content only needs a browser and about two lines of JavaScript to decrypt it.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

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