SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2003
    Location
    PA
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ampersand - Querystring Ugh!

    I am trying to pass a variable in the URL to a popup window. One of the variables in the URL has a value of S&CSB. Whenever I try to get at this variable it returns only "S". I did URL encode the "&" ampersand (%26) and (&amp and (S%26amp%3B), so I don't get why it's not working. Looks to me like ASP Request.Querystring is parsing from the ampersand on. I put the code below.

    Thanks for your thoughts!

    Code:
    <%@ Language=VBScript %>
    <html>
    <head>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <script language=javascript>
     var curPopupWindow = null;
     function openPopupFocus(url, name, pWidth, pHeight, features, snapToLastMousePosition, closeOnLoseFocus) {
      alert(url)
    	closePopup();
    	if (snapToLastMousePosition) {
    		if (lastMouseX - pWidth < 0) {
    			lastMouseX = pWidth;
    		}
    		if (lastMouseY + pHeight > screen.height) {
    			lastMouseY -= (lastMouseY + pHeight + 50) - screen.height;
    		}
    		lastMouseX -= pWidth;
    		lastMouseY += 10;
    		features += ",screenX=" + lastMouseX + ",left=" + lastMouseX + ",screenY=" + lastMouseY + ",top=" + lastMouseY;
    	}
    	if (closeOnLoseFocus) {
    		curPopupWindow = window.open(url, name, features, false);
    		curPopupWindow.focus ();
    	} else {
    		// assign the open window to a dummy var so when closePopup() is called it won't be assigned to curPopupWindow
    		win = window.open(url, name, features, false);
    		win.focus ();
    	}
    }
    function closePopup() {
    	if (curPopupWindow != null) {
    		if (!curPopupWindow.closed) {
    			curPopupWindow.close();
    		}
    		curPopupWindow = null;
    	}
    }
     
    </script>
    <script language=JavaScript RUNAT=SERVER>
    // This function decodes the any string
    // that's been encoded using URL encoding technique
    function URLDecode(psEncodeString) 
    {
      return unescape(psEncodeString); 
    }
    </script>
    </head>
    <body>
    <br><br>
    This page CLEAN popup...
    <br>
    <%Response.Write("subgroup= " & URLDecode(Request.Querystring("subgroup")))%>
    <br>
    <a href="javascript:openPopupFocus('SalesTest.asp?countrycode=01&subgroup=S%26CSB&currencycode=01');">Test %26</a><br><br>
    <a href="javascript:openPopupFocus('SalesTest.asp?countrycode=01&subgroup=S%26amp%3BCSB&currencycode=01')">Test %26amp%3B</a><br><br>
    <a href="javascript:openPopupFocus('SalesTest.asp?countrycode=01&subgroup=S&amp;CSB&currencycode=01');">Test &amp;</a><br><br>
    <a href="javascript:openPopupFocus('SalesTest.asp?countrycode=01&subgroup=S%26CSB&currencycode=01');">Test %26</a><br><br>
    <a href="javascript:openPopupFocus('SalesTest.asp?countrycode=01&subgroup=S&CSB&currencycode=01')">Test amp;</a><br><br>
    <br><br><br><br>

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i had this problem recently when using an asp frame, and trying to show a webpage that contained querystrings.

    I had to change them:

    ie. http://www.domain.com/frame.asp?prel...ah&blah1=blah1

    to

    http://www.domain.com/frame.asp?preload=1&location=http://www.domain.com/page.asp|blah=blah||blah1=blah1

    then use

    replace(request.querystring("location"),"|","?")
    replace(request.querystring("location"),"||","&")

    Which then worked because it wouldn't parse the |'s as asp coding, so when it came to the frame opening it up, as we have used replace to change these after the page has been parsed.

    So when your pop up is called, it will see what you require, but before hand it will only see | and || or what ever you choose as the replacements.

    Cheers

    Gav

  3. #3
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts
    replace(request.querystring("location"),"|","?")
    replace(request.querystring("location"),"||","&")
    wrong way round the first will replace both "||" that is required for the second.
    Code:
    replace(request.querystring("location"),"||","&")
    replace(request.querystring("location"),"|","?")
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    True, thanks for pointing out the mistake.

    Gav


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
  •