Jump to content
Sign in to follow this  
metadata

using buttons to open a new page

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

Share this post


Link to post
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

Share this post


Link to post
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().

Share this post


Link to post
Share on other sites

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. :good:

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...