metadata Posted August 8, 2012 Share Posted August 8, 2012 (edited) I am trying to figure out the best way to display a button on a page that will open a new page on clicking. I have a function set up using JS that once the button is clicked will call the function and then I can enter the code there to do the redirection. I just need to find some documentation on writing this code. Is it also possible to make the button itself a link so that by clicking on the button you would effectively be clicking on a link as well? (I've already done redirection this way) Thanks Edited August 8, 2012 by metadata Link to comment Share on other sites More sharing options...
mru21 Posted August 8, 2012 Share Posted August 8, 2012 I think this may help?http://www.w3schools.com/html/html_links.asp Link to comment Share on other sites More sharing options...
metadata Posted August 8, 2012 Author Share Posted August 8, 2012 (edited) No that's just how to use links, which I understand. I'm trying to write a function in JavaScript where when a user clicks on a button it automatically sends them to another page (such as an order form page). I'm trying to figure out where I can find the documentation on writing the code inside the JS function to have to browser open up the new page. Below is a brief example of what I'm trying to do in the code: <!DOCTYPE html> <html><head> <script type="text/javascript">function orderPage(){ }</script> </head><body> <button type="button" onclick="orderPage()">Order Now</button> </body> </html> Edited August 8, 2012 by metadata Link to comment Share on other sites More sharing options...
mru21 Posted August 8, 2012 Share Posted August 8, 2012 like this<form><input type="button" value="Put Your Text Here" onClick="window.location.href='http://www.hyperlinkcode.com/button-links.php'"></form> Link to comment Share on other sites More sharing options...
metadata Posted August 8, 2012 Author Share Posted August 8, 2012 I see, yes that works. thanks! Link to comment Share on other sites More sharing options...
ShadowMage Posted August 8, 2012 Share Posted August 8, 2012 What you're looking for is the location object. If you want to maintain browsing history, use the assign() function. This will enable the user to hit the Back button to get back to the previous page. The replace() function replaces the current page in the history. For example, the user is on Page A. Then goes to Page B which has your button on it. The button takes the user to Page C. If assign() is used to get to Page C, hitting Back will take the user back to Page B. If replace() is used, it will take the user to Page A, since Page B was replaced in the history by Page C. I am not sure how modifying the href attribute handles history, but I would assume it would act like replace(). Link to comment Share on other sites More sharing options...
metadata Posted August 8, 2012 Author Share Posted August 8, 2012 Yes I like that much better, gives more options in the handling of direction from the current page. Thank you that was what I was looking for. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now