Help - Search - Members - Calendar
Full Version: URL/HTML page verification
MSFN Forums > Coding, Scripting and Servers > Web Development (HTML, Java, PHP, ASP, XML, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
Sean1978
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
jcarle
It can't be done using JavaScript on the Client side.
ripken204
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.
Sean1978
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
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
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.



CODE
<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>
</form


this is just a sample code. hope you find it helpful
Idontwantspam
Submit to a URL with a query string (a ? after the .html) like this:

CODE
onClick="window.location.href='http://servername/folder/' + pname.value + '/index.html?goto'">


Then, on the 404 page...

CODE
<body onload="function check_error()">
...
<script type="text/javascript">
function check_error() {
<!--
var a = location.search
if (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.
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.