Jump to content

URL/HTML page verification


Recommended Posts

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 by Sean1978
Link to comment
Share on other sites


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 by ripken204
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 1 month later...

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

this is just a sample code. hope you find it helpful

Link to comment
Share on other sites

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.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.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...