467,122 Members | 1,296 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,122 developers. It's quick & easy.

i do not understand this behavior: url tacked onto "localhost"

I'm trying to use a LinkButton with both an HREF and an OnClick to defeat
the popup blocker because we have a disproportionately high number of users
who won't know they have popups blocked or even know what a popup is. Our
site opens pages from our affiliates in a popup window.

Why do I get an error saying page http://localhost/www.msn.com cannot be
found? How is 'localhost' entering into the picture? I assume there's a
conflict between the href and the onclick? I'm running the page inside
Visual Studio .NET

In the HTML document:

<script language="javascript">

function LAUNCH(url) {
alert('launch');
window.open(url);

}
</script>

In the code behind:

Public Class WebForm1

Protected WithEvents LB As LinkButton
Private Sub Page_Load (....
LB = New LinkButton
LB.ID = "Test1000"
LB.Attributes("ctrid") = "2468"
Dim url As String = "ht" + "tp:\\" + "www.msn.com"
LB.Attributes("onclick") = "ja" + "vascript:LAUNCH('" + url + "');"
LB.Text = "This is a test link whose click should open a popup"
AddHandler LB.Click, AddressOf TestLinkButtonHandler
Me.Panel1.Controls.Add(LB)

End Sub

Private Sub TestLinkButtonHandler(ByVal sender As System.Object, ByVal e As
System.EventArgs)

End Sub
The rendered HTML:
<a id="Test1000" ctrid="2468"
onclick="javascript:LAUNCH('http:\\www.msn.com');"
href="javascript:__doPostBack('Test1000','')">This is a test--it should
open a popup</a>

Nov 19 '05 #1
  • viewed: 2366
Share:
1 Reply
in javascript url = http:\\www.msn.com

\ is an escape character meaning the actual value is http:\www.msn.com

typically you escape a string in codebehind for use in javascript:

public shared function PrepareStringForJavascript(input as string) as string
if input is nothing then
return ""
end if
return input.replace("\", "\\").replace("'", "\'")
end if

so if you pass your dim url through this, it should work...

also slashes normally go the other way...http://www.msn.com which will also
solve your problem since / isn't a special character.

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Timo" <Ti**@noneofyer.biz> wrote in message
news:Oy**************@TK2MSFTNGP09.phx.gbl...
I'm trying to use a LinkButton with both an HREF and an OnClick to defeat
the popup blocker because we have a disproportionately high number of users who won't know they have popups blocked or even know what a popup is. Our
site opens pages from our affiliates in a popup window.

Why do I get an error saying page http://localhost/www.msn.com cannot be
found? How is 'localhost' entering into the picture? I assume there's a
conflict between the href and the onclick? I'm running the page inside
Visual Studio .NET

In the HTML document:

<script language="javascript">

function LAUNCH(url) {
alert('launch');
window.open(url);

}
</script>

In the code behind:

Public Class WebForm1

Protected WithEvents LB As LinkButton
Private Sub Page_Load (....
LB = New LinkButton
LB.ID = "Test1000"
LB.Attributes("ctrid") = "2468"
Dim url As String = "ht" + "tp:\\" + "www.msn.com"
LB.Attributes("onclick") = "ja" + "vascript:LAUNCH('" + url + "');"
LB.Text = "This is a test link whose click should open a popup"
AddHandler LB.Click, AddressOf TestLinkButtonHandler
Me.Panel1.Controls.Add(LB)

End Sub

Private Sub TestLinkButtonHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub
The rendered HTML:
<a id="Test1000" ctrid="2468"
onclick="javascript:LAUNCH('http:\\www.msn.com');"
href="javascript:__doPostBack('Test1000','')">This is a test--it should
open a popup</a>

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Chris | last post: by
4 posts views Thread by Greg Cyrus | last post: by
12 posts views Thread by Jonathan Wood | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.