Jump to content

using buttons to open a new page


metadata

Recommended Posts

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 xD

Edited by metadata
Link to comment
Share on other sites

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

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

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
×
×
  • Create New...