SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    May 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,789
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The only way you could do it with JavaScript is to have the JavaScript change the method from "get" to "post"
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Member
    Join Date
    May 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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>

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,789
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    <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>
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by felgall View Post
    <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?

    Code:
    if (window.location.search.substring(1) == "Screen=ACCOUNT") {
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,789
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    Won't that affect the Cart.html file though, which depends on the querystring?
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  7. #7
    SitePoint Member
    Join Date
    May 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •