Forum Moderators: open

Message Too Old, No Replies

input type=button

Replicating an anchor tag

         

Alternative Future

2:39 pm on Jun 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all,

We have the need to use the input button throughout our application for uniformity on the UI; these would be used between form submissions and replace the basic anchor tag.
My question is, using the onclick event we call on window.location = 'path'; what other options are available and what are the pros and cons between using each one.
i.e. we could use location.href = 'path';
Are there any other ones that are better or have another purpose, I am interested in all thoughts on the matter.

Many thanks,

-George

edit: the subject should have read replacing an anchor tag.

Bernard Marx

3:17 pm on Jun 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use location.href for setting and getting.

The result is the same with plain location, but location is an object, which will call it's toString() method if forced to. location.href really is a string. The last I heard, it's best to use

[blue]window.location.href = "url"[/blue]

since there's no guarantee that Xbrowser version won't stop supporting the other syntax that uses the location object as a setter property.

PS. AFAIK, there's no particular reason to use window. . As with all window props & methods [alert,open ..] they are considered global. Thus, if we threw caution to the wind, you could just do:

[blue]location = "url"[/blue]

or have another purpose

[blue]location.replace("url")[/blue]

This has the effect of replacing the current page with the new. Clicking the back button results in going back to the page before our current one, which is no longer 'there'. Perhaps useful to stop conflicting form input.

Then there's others which may be more proprietary

[blue]window.navigate("url")[/blue]

[edited by: Bernard_Marx at 3:29 pm (utc) on June 25, 2004]

Alternative Future

3:24 pm on Jun 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Bernard Marx,

Yeah I heard that document.location is/will no longer be supported.


Previous versions of JavaScript have encouraged programmers to use document.location and document.location.href to achieve the same effects described in this article. However, this practice should be avoided because Netscape Communications recently announced that in future versions of JavaScript, location will no longer exist as a property of the document object. In its place, document.URL will continue to be available, but only as a read-only string.

I think what you have said is the best way forward as it is interpreted as a string.

-George

Bernard Marx

3:34 pm on Jun 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's interesting I didn't know¦forgot that.

Notice there that document's property is being used. Whether that quote has any bearing on use of window.location, I don't know. Also, whether Netscape Com, as opposed to Mozilla, has any say in future matters is also iffy.

I can say this for certain, though. If any browser maker decides to stop supporting window.location.href as a setter, then they are close to paying their executioner.