slashjack Posted October 14, 2011 Share Posted October 14, 2011 Hi guys i want some help with a simple problem i have.Okay so im a new student and i have this website http://geeksqueaks.co.uk. Im trying to do this thing where the user clicks a button, this opens a message box, which the user then puts in a password, if the word is correct i want to be able to show a document.I hope this makes sense! Thanks guys Link to comment Share on other sites More sharing options...
justsomeguy Posted October 14, 2011 Share Posted October 14, 2011 Javascript doesn't provide any security for that type of thing, is PHP an option? You can still use Javascript to send an ajax request to PHP to check the password and return the filename, but if you have things like the path to the file or the password checking in Javascript code then anyone can read that. Link to comment Share on other sites More sharing options...
slashjack Posted October 14, 2011 Author Share Posted October 14, 2011 yeah i know it will be open, i dont mind, its not for secure stuff Link to comment Share on other sites More sharing options...
justsomeguy Posted October 15, 2011 Share Posted October 15, 2011 You can use the window.prompt function to get the password. If the password is correct then you can use window.open to open the link to the document in a new window, or you can set window.location.href to redirect the current page to the document. Link to comment Share on other sites More sharing options...
eTianbun Posted October 15, 2011 Share Posted October 15, 2011 eg: function passkey(){password=window.prompt('Enter password','');if(password=='This'){window.open('http://www.domain.com/page.html')}else{alert('Please enter a valid password!')}} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.