Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 426
  • Last Modified:

Removing query string from new window opening up - Java Script

I have the following code in an ASP .net  web page to open up a new window:

Dim jstring As String = "<script language='javascript'>"
        jstring &= "var newwin=window.open('http://gisapp/newview/onpoint?DEFAULTSKIN=default&LINK=true&PROJECT=Basemap&MAPTAB=AnimalControl&LINKTYPE=QUICKSEARCH&SEARCHITEM=AnimalCalls&quicksearch.x=true&LOGIN=USER&searchvalue=" & _
        txtBlockLotNo.Text & "','_blank');var loc=new String(newwin.location);newwin.location=loc(substring(0,loc.indexOf('?'));"
        jstring &= "</script>"
        Page.RegisterStartupScript("test2_", jstring)

I want to remove the query string from the URL of the new window being opened so that sensitive information is not seen by the user.  However, this code results in no window being openned up.  Points to whoever can fix this so it works.
0
Kaporch
Asked:
Kaporch
1 Solution
 
KaporchAuthor Commented:
I need to remove the query string portion of the URL.  How do I do that?
0
 
ZvonkoSystems architectCommented:
Check this:

Dim jstring As String = "<script language='javascript'>"
   jstring &= "var loc='http://gisapp/newview/onpoint?DEFAULTSKIN=default&LINK=true&PROJECT=Basemap&MAPTAB=AnimalControl&LINKTYPE=QUICKSEARCH&SEARCHITEM=AnimalCalls&quicksearch.x=true&LOGIN=USER&searchvalue=" & _
        txtBlockLotNo.Text & "';var  nW=window.open();nW.document.write(\"<iframe src='\"+loc+\"' width='100%' height='100%'></iframe>\");loc=loc.split('?')[0];"
        jstring &= "</script>"
        Page.RegisterStartupScript("test2_", jstring)



0
 
KaporchAuthor Commented:
I had to change some of the quotes in your string, Zvonko, because I was getting an error the way it was.  When I corrected it like this:

Dim jstring As String = "<script language='javascript'>"
jstring &= "var loc='http://gisapp/newview/onpoint?DEFAULTSKIN=default&LINK=true&PROJECT=Basemap&MAPTAB=AnimalControl&LINKTYPE=QUICKSEARCH&SEARCHITEM=AnimalCalls&quicksearch.x=true&LOGIN=USER&searchvalue=" & _
            txtBlockLotNo.Text & "';var  nW=window.open();nW.document.write(\'<iframe src='\'+loc+\'' width='100%' height='100%'></iframe>\');loc=loc.split('?')[0];"
jstring &= "</script>"
 Page.RegisterStartupScript("test2_", jstring)

The new page still doesn't open.
0
 
dbrittCommented:
You're escaping incorrectly for VB. When you make your string, those backslashes are going to stay in there as literals and try to be interpreted by JS. To escape double quotes in VB, either use the VB code or use double-double quotes, like this: ""

I just eyeballed this code and tried to make the correct changes, if I missed a spot, your compiler should tell you where, just make sure your escape sequences are correct. Cheers.

==================================================

Dim jstring As String = "<script language='javascript'>"
jstring &= "var loc='http://gisapp/newview/onpoint?DEFAULTSKIN=default&LINK=true&PROJECT=Basemap&MAPTAB=AnimalControl&LINKTYPE=QUICKSEARCH&SEARCHITEM=AnimalCalls&quicksearch.x=true&LOGIN=USER&searchvalue=" & _
            txtBlockLotNo.Text & "';var  nW=window.open();nW.document.write(""<iframe src='""+loc+""' width='100%' height='100%'></iframe>"");loc=loc.split('?')[0];"
jstring &= "</script>"
 Page.RegisterStartupScript("test2_", jstring)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now