Sean1978 Posted May 16, 2007 Posted May 16, 2007 (edited) Very simply, I have a top level webpage that is used to open other webpages<input type="text" name=PageName ID=pname value="123456" size=12><input type=button value="Open Page" onClick="window.location.href='http://servername/folder/' + pname.value + '/index.html'"></form>It works for what I want, but if I choose a page name that does not exist, I get the all-mighty 404. I'm not a web dev, so this isn't my particular area of specialty. I read about doing it server side, but I would really rather avoid that.Anyone have any suggestions for how to implement a simple URL check into the onClick event to verify the webpage referenced by window.location.href exists? If it exists, it is opened. If it does not exist, it spits out an error message and does nothing.TIA Edited May 16, 2007 by Sean1978
ripken204 Posted May 16, 2007 Posted May 16, 2007 (edited) so why exactly are you having this problem? do you have lots of buttons going nowhere? if so you should find out why and fix it. if you can edit your 404 file you could have it automatically bring you back to the page you were just at. Edited May 16, 2007 by ripken204
Sean1978 Posted May 17, 2007 Author Posted May 17, 2007 As the code above shows, I have a textbox and a single button. A user can enter any value. If they enter a value that leads to a non-existent page, then it 404s. I'm an application programmer; to me, it is very odd to not be able to verify the existence of a file/object from the client side with a simple check.Thanks for the replies. I'll start looking at altering the error handling on the server for 404s.
ripken204 Posted May 17, 2007 Posted May 17, 2007 well im just curious. why do you have the user typing in a page and clicking on a button? you should restrict the user to certain pages and have links to those pages.
Muhammad Kashif Majeed Posted July 12, 2007 Posted July 12, 2007 hello, I think its better if you use a dropdown menu in place of textbox. and on its change option redirect user to the page from your website.<form name="quickLink"> <select name="menu" onChange="location=document.quickLink.menu.options[document.quickLink.menu.selectedIndex].value;" size="1" > <option value="#" selected>Quick Links ...</option> <option value="http://yourwebsite address/your_page.htm">Page Title here</option> </select></formthis is just a sample code. hope you find it helpful
Idontwantspam Posted July 13, 2007 Posted July 13, 2007 Submit to a URL with a query string (a ? after the .html) like this: onClick="window.location.href='http://servername/folder/' + pname.value + '/index.html?goto'">Then, on the 404 page...<body onload="function check_error()">...<script type="text/javascript">function check_error() {<!--var a = location.searchif (a == "?goto") {history.back(1);}}// --></script>So, if the 404 page is gotten when trying to go to a page from this form, it will bounce back. Or, use server-side for the 404 page only. It's helpful to have server-side for 404 pages anyway.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now