How do I insert a link to another page to the pressing of a button? I'm assuming it would be via the onclick event, but can't seem to get it accomplished in a manner which will actually work.

Recommended Answers

I'm assuming it would be via the onclick event

Have you tried:

window.location = "???.html";
Jump to Post

All 3 Replies

I'm assuming it would be via the onclick event

Have you tried:

window.location = "???.html";

Alright, thanks!

Though that works, it's an incorrect way of doing things.

The location property of the global object window is an object and not a string. What you need to do here is set the href attribute or property of the location object. And BTW, no need to prepend it with window since it is implied. location.href = 'http://www.google.com/'; And come to think of it, there is no need to drag javascript into this. You can do this with simple HTML assuming you don't need to dynamically generate the link. <a href="http://www.google.com/"><input type="button" value="Go!!" /></a>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.