Using a Form to Dynamically Change the URL in the

2019-09-19 07:17发布

I'm developing a Volusion site, and as a method of adding items to the cart, I want potential customers to be able to enter a product code to automatically add that product to the cart.

So, I need a form that will completely replace what's in the address bar with:

http://www.yourvolusionstore.com/ShoppingCart.asp?ProductCode=

And then I need a field where they put in the product code and the code gets added at the end...I've been browsing for an answer to this everywhere, but nothing seems to work...

2条回答
贼婆χ
2楼-- · 2019-09-19 08:05

Do you mean, you want to do a redirect? There are only 2 ways to change what is in the address bar:

  1. By navigating the user to a different page, using one of several methods to do that.
  2. By changing the hash, using one of several methods to do that.

Other than that, you can't change the URL without navigating them to the page you are changing it to. If you want to send them to that page, you can do:

window.location.href="http://www.yourvolusionstore.com/ShoppingCart.asp?ProductCode=";

If you want to change the hash, you can do

window.location.hash='foo';

that would change the url from http://www.yourvolusionstore.com/ShoppingCart.asp to http://www.yourvolusionstore.com/ShoppingCart.asp#foo without navigating away from the page.

If you are trying to accomplish something else, please clarify that in your question.

查看更多
再贱就再见
3楼-- · 2019-09-19 08:10

There are several methods in Volusion to add products to the cart but this is about as basic as it gets.

<form action="ShoppingCart.asp" name="form" method="get">
    <input type="text" value="" name="ProductCode">
    <input type="submit" value="Add To Cart">
</form>
查看更多
登录 后发表回答