Jump to content

Javascript Links.. Always The Same Url


smerny
 Share

Recommended Posts

Hey, I'm not sure if this is the right place... but I've noticed that on some sites when you hover a link it says something like java script:Submit('menu_home') in the status bar... and if you click on a link, a new page loads but the URL in the address bar stays the same...Can someone explain what the purpose of this is? and how it is done?

Link to comment
Share on other sites

You can use the <a> tag to create a clickable area of text that looks like a link, but it triggers a JavaScript function, like this:

<a href="java script:welcome()">Hi!</a>

It gives the impression of a link, with the benefits of adopting the same styling as a link, without the (tiny) hassle of explicitly setting an onclick event.

Link to comment
Share on other sites

why do people do that instead of linking a page? and how does it load and display a new page without changing the URL in the address bar?

Link to comment
Share on other sites

JavaScript functions can create page redirects and start the ball rolling on certain modular site design changes, I think, though my knowledge of AJAX is non-existant at present, so I don't know the means of the latter. For example, you can use JS to do form input verification and, if everything is okay, submit the form like normal, which will create a response from a php script, part of which will generate a new page or return some message or perform any number of other actions. JavaScript can also easily find page elements, like DIVs, Ps, SPANs, etc. etc. and change their content or toggle display on and off, giving the appearance of an instantaneous page change.

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
 Share

×
×
  • Create New...