Preventing an HTML page save/download

Discussion in 'Programming' started by AHA7, May 2, 2007.

  1. #1
    Hello,

    Is there anyway to prevent people from downloading an HTML document from my website using JavaScript or some other client-side programming language?
    For example, my page is located at: "http://mysite.com/dir/page.html", how can I 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,...
     
    AHA7, May 2, 2007 IP
  2. SeLfkiLL

    SeLfkiLL Active Member

    Messages:
    85
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    50
    #2
    It's not possible to prevent people from downloading pages from your website, since basically, that's all a browser does. You can make it hard by using JavaScript, but it won't stop people who are determined. For example, I can just use wget to download pages as files. So if you're trying to hide something, don't expect it to be very secure.
     
    SeLfkiLL, May 2, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
  4. nabiha

    nabiha Peon

    Messages:
    111
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi,

    I will have to say "YES" may be it is possible.
    I know some seniors here has said otherwise but still cant help it. I have to say yes it is possible to almost hide (if not completely hide html).

    What can be done is to have a HTML page only include a javascript file example: xyz.js

    In that xyz.js file the code only call a php file in Javascript tag passing document.url as a parameter.

    Now finally that php file will output the HTML contents in javascript document.write format. Now you can add additional check to that php file by checking document.url passed as parameter and also checking the HTTP referer. HTTP referer and document url should be valid for your server inorder for php to output document.write otherwise HALT.

    If a person will try to save the page, he will save HTML page with a xyz.js which also has nothing. If he tries to call php file it wont work until and unless he fakes referer (which I am not saying is impossible). So inshort it will be extremely difficult to get the code. You can make it further hard by using random parameters for each request/connection pair to know that for a request of your HTML page, JS is issued and is never directly called and to further ensure that for a single request of HTML page js is served single time.

    I think it will work to some extent. Experts please tell me your thoughts.
     
    nabiha, May 3, 2007 IP
  5. Codythebest

    Codythebest Notable Member

    Messages:
    5,764
    Likes Received:
    253
    Best Answers:
    0
    Trophy Points:
    275
    #5
    No way. You can reverse engenering any .js out there and retrieve PHP code or whatever. I can send you by email any html of any site out there...
     
    Codythebest, May 3, 2007 IP
  6. nabiha

    nabiha Peon

    Messages:
    111
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It is great offer Cody, can I please PM you the link. i have tried several times but I couldnt get into the JavaScript code. I am not interested in the code, I am interested in knowing how they are blocking their HTML source and how it can be broken.
    Just to add, I never claimed it will make it impossible. I said it will make it extremely difficult.
     
    nabiha, May 3, 2007 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    Could you PM me the link as well? :)
     
    nico_swd, May 3, 2007 IP