Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open url in same browser everytime

Status
Not open for further replies.

halfbarrel

Programmer
Jun 12, 2002
44
US
Hello,
Can anyone tell me how from a vb app you can open a url into the same browser window everytime, or if it is possible? At work a programmer from one of our vendors is using ShellExecute currently to open the browser, and I've done some searching, but am not that great of a vb programmer myself. Any help would be greatly appreciated.
Thanks,

Chris.
 
Please clarify what you mean by the "same browser window every time". Do you mean that you'd like to make sure that a URL is opened in, say, IE instead of Mozilla Firefox? Or do you mean that you'd like to make sure that the URL opens in a given instance of a browser?

Also, why is it relevant to the problem at hand that the programmer you mention is using ShellExecute, and which browser is "the" browser that he's opening?
 
What I mean is that I would like it to open in the same instance everytime. So for instance if they click the button twice they would still only have one browser open it would just get reloaded. I thought it might be important to say how the programmer is currently opening the window so if there was a way to do it will ShellExecute it would minimize the amount of code change needed. Also, it is opening in IE(version 6 on my pc) although I don't think he is hard coding IE that's just all I have on my pc and throught the corporation in fact.

Once again, thanks for any help.


Chris.
 
Ok, so you are saying that within the context of your VB app, you want one and only one instance of IE to be running. Is that correct? Also, can you verify that you are ok with the user opening an instance of IE outside of your VB app? And also, what have you done so far?
 
I think this is the same problem that I came across a few years ago.
On machines running IE5 only one instance opened but if the machine had IE6 on it then a new instance opend every time.

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Bob,
That's correct, I would if possible like it to open a browser if the app hadn't open one yet, and if it had reuse that browser. Yes, I am okay with end users opening other browsers.

I haven't done much so far just a little research.

Thanks,

Chris.
 
One question that may help me is can I use the return value from shellExecute to close the window or identify if the window is still open?
Thanks again,

Chris
 
I don't know that I would do it that way. It's actually very simple to do this with the IE Dll. To demonstrate this, open a new VB project and set a reference to "Microsoft Internet Controls." Then add the following code:
Code:
Option Explicit

Private Sub Command1_Click()
Static ie As InternetExplorer
If ie Is Nothing Then
    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate2 "[URL unfurl="true"]www.ibm.com"[/URL]
Else
    On Error Resume Next
    ie.Navigate2 "[URL unfurl="true"]www.tek-tips.com"[/URL]
    If Err.Number <> 0 Then
        Err.Clear
        Set ie = Nothing
        Command1_Click
    End If
End If
End Sub

The error handler kicks in if you close the IE instance that the app has created and push the command button again.

HTH

Bob
 
Bob,
Thanks, that code looks great. I had came up with something pretty similar today, but I like what you've done better.

I know it kind of seems confusing, but the page that is getting opened is basically just a launcher window that does a window.open to open another named window. The window that is being named is basically a patient's medical record and could be opened from many spots that's why we need to name it, and that's the reason I don't want a whole bunch of these launcher windows just sitting around. One is okay, but they are pretty much useless after being launched.

Once again thanks for the help.
Chris.
 
What you're doing is an example of the singleton pattern, which has to do with keeping one and only one instance of an object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top