Open new browser window in vbscript.net

S

smokeyd

hi,

can anyone tell me how to open a link in a new browser window in
vbscript.net. i am looking to be able to set the properties such as
size, menu bar, scroll bar etc. or alternativelly is there a simple
way to do this in visual web developer?

many thanks in advance for your help.
 
J

John Timney \(MVP\)

Heres an example aspx page for you that shows you how to do it in vb.net.
This works in VWD.

<script runat="server">
Sub Page_Load( sender as Object,e as EventArgs)

Dim scriptString As String
scriptString = "<script language=JavaScript> function DoClick() {"
scriptString +=
"window.open('http://www.mvps.org','MyWindow','width=500,height=500');}<"
scriptString += "/"
scriptString += "script>"

If (Not ClientScript.IsClientScriptBlockRegistered("ClientScript"))
Then
ClientScript.RegisterClientScriptBlock(Me.GetType(),
"ClientScript", scriptString)
End If

End Sub

</script>

<html>
<body topmargin="20" leftmargin="10">
<form id="myForm" runat="server">
<input type="button" value="ClickMe" onclick="DoClick()">
</form>
</body>
</html>

--
--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog
 
M

Mark Rae

Hi John,
scriptString = "<script language=JavaScript> function DoClick() {"

That syntax is deprecated now, and won't produce XHTML-compliant markup.

Use this instead:

scriptString = "<script type=\"text/javascript\"> function DoClick() {"

Mark

P.S. Not a problem if you don't need cross-browser compatibility... ;-)
 
J

John Timney \(MVP\)

Just for clarity in the thread - for VB.NET the code is
scriptString = "<script type=""text/javascript""> function DoClick() {"

Full example below:
--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog

<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load( sender as Object,e as EventArgs)
Dim scriptString As String
scriptString = "<script type=""text/javascript""> function DoClick()
{"
scriptString +=
"window.open('http://www.mvps.org','MyWindow','width=500,height=500');}<"
scriptString += "/"
scriptString += "script>"

If (Not ClientScript.IsClientScriptBlockRegistered("ClientScript"))
Then
ClientScript.RegisterClientScriptBlock(Me.GetType(),
"ClientScript", scriptString)
End If
End Sub
</script>

<html>
<body topmargin="20" leftmargin="10">
<form id="myForm" runat="server">
<input type="button" value="ClickMe" onclick="DoClick()">
</form>
</body>
</html>
 
S

smokeyd

John said:
Just for clarity in the thread - for VB.NET the code is
scriptString = "<script type=""text/javascript""> function DoClick() {"

Full example below:
--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog

<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load( sender as Object,e as EventArgs)
Dim scriptString As String
scriptString = "<script type=""text/javascript""> function DoClick()
{"
scriptString +=
"window.open('http://www.mvps.org','MyWindow','width=500,height=500');}<"
scriptString += "/"
scriptString += "script>"

If (Not ClientScript.IsClientScriptBlockRegistered("ClientScript"))
Then
ClientScript.RegisterClientScriptBlock(Me.GetType(),
"ClientScript", scriptString)
End If
End Sub
</script>

<html>
<body topmargin="20" leftmargin="10">
<form id="myForm" runat="server">
<input type="button" value="ClickMe" onclick="DoClick()">
</form>
</body>
</html>

thanks for all of the help. the code needed a few little tweaks but
works great:

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim scriptString As String
scriptString = "<script type=""text/javascript""> function
DoClick() {"
scriptString +=
"window.open('popup.aspx','MyWindow','width=500,height=500');}<"
scriptString += "/"
scriptString += "script>"
If (Not
ClientScript.IsClientScriptBlockRegistered("ClientScript")) Then
ClientScript.RegisterClientScriptBlock(Me.GetType(),
"ClientScript", scriptString)
End If
End Sub
</script>


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HyperLink ID="HyperLink1" runat="server"
OnClick="DoClick()" NavigateUrl="#"> HyperLink</asp:HyperLink></div>
</form>
</body>
</html>

however visual web developer gives an error saying onclick is not a
valid attribute of element 'hyperlink' but seems to work okay anyway..
 
J

John Timney \(MVP\)

Yes, you can do that of course.

The hyperlink declaration should be changed to:

<asp:HyperLink ID="HyperLink1" NavigateUrl="#" runat="server" >
HyperLink</asp:HyperLink>

A quirk with using attributes.add - If you dont set the NavigateUrl property
and dont style it you will get a plain old clickable word.

Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
http://www.johntimney.com/blog
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top