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

T

Timo

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>
 
K

Karl Seguin

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!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top