Hide Querystring in address bar with javascript

Hello,

I have problem, I am using this code to get the shopping cart in Iframe when i click on the button. I am using GET method for this as I have to get the product id and value.

I have two pages, one for products and one for iframe where i have to load my shopping cart.

The code for both the page is below :

Product.html

<FORM METHOD=“get” ACTION=“cart.htm”><INPUT TYPE=“hidden” NAME=“Product_Code1” VALUE=“9781586487409”><INPUT TYPE=“hidden” NAME=“Quantity1” VALUE=“1”><INPUT TYPE=“submit” Value=“Buy Now”></FORM>

Cart.html

<iframe id=“frame1” height=“700” width=“620” scrolling=“auto” onload=“SetHeight()” style=“border:none;”>
</iframe>

<script language=“javascript” type=“text/javascript”>

 var ZnodeSitename = 'http://example.com'; //New Znode public Affairs URL.
 if (window.location.search.substring(1) == "Screen=ACCOUNT") {
     var objFrame = document.getElementById("frame1");
     objFrame.src = ZnodeSitename + "Account.aspx"

 }
 else if (window.location.search.substring(1) == "") {
     var objFrame = document.getElementById("frame1");
     objFrame.src = ZnodeSitename + "ShoppingCart.aspx"
 }
 else {
     var objFrame = document.getElementById("frame1");
     objFrame.src = ZnodeSitename + "WebServiceClass.aspx?" + window.location.search.substring(1);

 }

 function SetHeight() {
     var objFrame = document.getElementById("frame1");
     var the_height = objFrame.document.body.scrollWidth;
     objFrame.height = the_height

 }

</script>

Note : I do not want to show querystring in url and i cannot use url rewrite for this. Can we do this with some javascript. please help me, thanks in advance.

The only way you could do it with JavaScript is to have the JavaScript change the method from “get” to “post”

Thanks for the suggestion

Can you provide me the code to post the values of this form.

<FORM METHOD=“get” ACTION=“cart.htm”><INPUT TYPE=“hidden” NAME=“Product_Code1” VALUE=“9781586487409”><INPUT TYPE=“hidden” NAME=“Quantity1” VALUE=“1”><INPUT TYPE=“submit” Value=“Buy Now”></FORM>

<FORM METHOD=“post” ACTION=“cart.htm”><INPUT TYPE=“hidden” NAME=“Product_Code1” VALUE=“9781586487409”><INPUT TYPE=“hidden” NAME=“Quantity1” VALUE=“1”><INPUT TYPE=“submit” Value=“Buy Now”></FORM>

Won’t that affect the Cart.html file though, which depends on the querystring?


if (window.location.search.substring(1) == "Screen=ACCOUNT") {

Yes but changing it to post is the only way to hide the querystring and so the other page would need to be changed to use server side scripting to read the data. The only purely JavaScript solution leaves the OP with the querystring displayed which isn’t what they want.

Hey

How about redirecting the page again to cart.html ?

so that the querystring will be removed and the quantity would not get updated everytime we refresh the page.