Link to home
Start Free TrialLog in
Avatar of mos
mos

asked on

Showing Web-Page in a Browser from Applikation ?

How can I open a Web Page in a Browser from a Java Applikation ?
I wanna send a URL from a Java Applikation to the default Browser on the System (e.g. IE, Communicator)!
Further more I want to decide if the page will open in a new
Browser-Window or in an old one!

Thanks for helping
Avatar of gadio
gadio

mos, Use the java.lang.Runtime.exec command to invoke the browser, and send the page as a parameter. About displaying a URL in a currently open browser, there is no uniform way to do that. The communicator has an interface for 'remote activation' of URLs but the Explorer mechanizem is different. In any case hooking into these interfaces may prove to be quite complicated. The exec approach is probably more cost effective.

I comment this answer so that someone may answer better regarding the displaying of URLs in a currently open brawser.

G.
But how to get the "Default" browser program and it's pathname?
I think we need a native method to help us to find it out.
Avatar of mos

ASKER

Threshold, you are right.
I really need a way to get the "default" browser and the possibility to open pages in an old window (preventing to open hundreds of different browser windows)!
So, how does the nativ method look like on a win32 system ?

ASKER CERTIFIED SOLUTION
Avatar of jdyer
jdyer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you want it to run in NT....
In NT Resource Kit, You can find the tool(RegGet.exe... i forgot the name...) to get informations from NT Registry.
So. use the Runtime.exec() to run the tool.

First, you get the HKEY_CLASSES_ROOT/.html/Content Type = NetscapeMarkup

Second, you can find HKEY_CLASSES_ROOT/MetscapeMarkup/open/command =
                     C:\PROGRA~1\Netscape\COMMUN~1\Program\netscape.exe "%1"

Then you can find the default browser to open .html file... and use Runtime.exec() to open any document with C:\....\netscape.exe

[jdyer] - If the window handler is a must, than that may present a problem, since through JNI its not easy to get a HWND of the java application.
teh window handler is only the handler of the parent window. Thus, just send null, and the parent will be the desktop. How does that sound?
teh should be "the"

Sorry, so instead of above in my proposed answer, it SHOULD be

ShellExecute( null, "open", "http://www.yahoo.com", null, getProperties( "acl.write" ), 1 );

The First arg is null because we want the window's parent to be the desktop;

The Second arg is "open" because we want to open http://www.yahoo.com

The Third arg is "http://www.yahoo.com" because we want to connect to Yahoo! (this can be anything.

The Fourth arg is null because we don't want any parameters

The fifth is the current directory for the application, this can be anything really, I just chose the directory where applets can write to

The fifth is SW_SHOWNORMAL (which equals 1) because that is the type of window we want.

Hopefully that will clarify things a bit

Regards,
  jdyer