Question Open new default browser window from button

brekke

Member
Joined
Oct 17, 2010
Messages
11
Location
Stavanger, Norway
Programming Experience
Beginner
Hi guys..

Just a quick qquestion.
My application opens a web browser window with the click of a button.
Today it looks like this:

Process.Start("http://www.google.com" + researchnr1.text)
(It's not this website, but this is just an example.) This will open the requested website with a specified number at the end of the adress.

What i would like it to do was to run like the simple html command would run it:
javascript:void(window.open ('http://www.google.com','Mainframe','menubar=no,toolbar=no,location=no,scrollbars=yes,status=no,resizable=yes'))
And ofcourse the specified tag from the text field at the end.
Is there anyway to convert this into working with VB?

Thanks in advance..
 
'Just Found this online, was looking for it myself. it works great and should serve your purpose with a few modifications.
'By Zebula8


Public Class Form1

Friend Function GetDefaultBrowser() As String
Dim browser As String = [String].Empty
Dim key As Microsoft.Win32.RegistryKey = Nothing
Dim Quote As String = Chr(34)
Try

key = My.Computer.Registry.ClassesRoot.OpenSubKey("HTTP\shell\open\command", False)

' trim off quotes
browser = key.GetValue(Nothing).ToString().ToLower().Replace(Quote, "")
If Not browser.EndsWith("exe") Then
' get rid of everything after the 'exe'
browser = browser.Substring(0, browser.LastIndexOf(".exe") + 4)

End If

Finally
If key IsNot Nothing Then
key.Close()
End If
End Try

Return browser

End Function

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim p As New Process()
p.StartInfo.FileName = GetDefaultBrowser()
p.StartInfo.Arguments = "www.yahoo.com"
p.Start()
End Sub
End Class
 
FluidOne, that is all redundant since that is what Process.Start(url) does, it also doesn't answer the question actually asked.

To execute a javascript you could use a hidden WebBrowser control and set DocumentText, for example add a script and call .Document.InvokeScript method, or add a dummy element with onload directive.
For window.open specifically you could just navigate to an empty document and use .Document.Window.Open function as exposed by HtmlWindow class.
A second thought, why not show the document directly in WebBrowser control in form? If you need a separate window simply add another form for it.
 
FluidOne, that is all redundant since that is what Process.Start(url) does, it also doesn't answer the question actually asked.

To execute a javascript you could use a hidden WebBrowser control and set DocumentText, for example add a script and call .Document.InvokeScript method, or add a dummy element with onload directive.
For window.open specifically you could just navigate to an empty document and use .Document.Window.Open function as exposed by HtmlWindow class.
A second thought, why not show the document directly in WebBrowser control in form? If you need a separate window simply add another form for it.

Thanks.. :)
Should this work if i try to execute the java script command on an external webrowser, say for instance firefox or IE?
 
Should this work if i try to execute the java script command on an external webrowser, say for instance firefox or IE?
That would be redundant as well, since you would be opening a new browser window for the only reason of opening another browser window.
 
Back
Top