Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Opening a URL in the user's browser  (Read 4880 times)
0 Members and 1 Guest are viewing this topic.
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Posted 2003-10-24 04:49:15 »

My first thread in newless clubies Smiley

So what is the best way to load up a browser when a user clicks a link?

I have some HTML help documentation that I would like loaded up in a browser.  One option I guess is to use a Java HTML renderer but I think a full browser is better suited.

For windows the best way of loading a URL I can see is "start http://google.com/".  This will load the URL in the user's default browser.

For other OS's it gets a bit harder.  I don't like the idea of making an assumption for linux that a user has one browser or another, for example old code used to assume "netscape" but now many people don't use that and use mozilla instead.

So I guess my choice is test for the existance of a particular browser (this could be changed in a user config file) and if none is found just display a box saing "goto http://google.com" - or just display the box first up.

There exists a Sourceforge project that has the right ideas http://browserlauncher.sourceforge.net/ but is too old now.  Which presents a problem in itself - I don't want to update this code every year so somthing which lasts is better.  So is this windows "start" command going to be around for a while?

This article I also found but was of little help:
http://www.javaworld.com/javaworld/javatips/jw-javatip66.html
as i can't see "rundll32 url.dll,FileProtocolHandler http://www.javaworld.com" being any better than a simple "start" command (I wounder if the author even knew about that command?).

I believe that "start" should run in windows 98 in the manner I am using it (file associations) as this document suggests: http://www.lagmonster.org/docs/DOS7/y-start.html

Does anyone have any experiances with this that they can share?  Is there any magical way around this problem?  Will Java1.5 have some spiffy method like "System.openURLInBroswer"  Cool?

The best I have thus far  is to use "start" with windows, and in linux test for the existance of "mozilla", if it exists then use it else just show a text box.  Enabling the user to change the linux/otherOS binary from "mozilla" to somthing else could help although it's still not ideal.

Thanks  in advance,

Will.

Offline princec

JGO Kernel


Medals: 282
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2003-10-24 10:36:29 »

I just used that old browserlauncher code. It'll have to do for now, but yes, it really needs an API call.

Cas Smiley

Offline Jens

Senior Member




Java for games!


« Reply #2 - Posted 2003-10-24 11:31:17 »

You may try checking the $BROWSER environment variable and (after that) the /usr/bin/x-www-browser symlink. It's not perfect.

Xith3D Getting Started Guide (PDF,HTML,Source)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tortoise

Junior Member




<3 Shmups


« Reply #3 - Posted 2003-10-24 16:13:03 »

And if all else fails (and it almost certainly will in Linux), why not resort to Swing's HTML interface? That's better than a "sorry can't do it" message.
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #4 - Posted 2003-10-24 19:42:02 »

http://browserlauncher.sourceforge.net

Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #5 - Posted 2003-10-26 01:02:59 »

Quote
And if all else fails (and it almost certainly will in Linux), why not resort to Swing's HTML interface? That's better than a "sorry can't do it" message.


I guess so - for help files, but what if like in Alien Flux's case you are trying to sell them somthing etc?

Thanks,

Will.

Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #6 - Posted 2003-10-26 01:04:02 »

Quote
You may try checking the $BROWSER environment variable and (after that) the /usr/bin/x-www-browser symlink. It's not perfect.


neither of those is setup on my system Sad  - pity if it was a standard it would be great...

Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #7 - Posted 2003-10-26 01:07:33 »

cas, so browserlauncher will work in all versions of Windows will it?

My only question is why they would use "rundll32 url.dll,FileProtocolHandler" and not just "start"?

They really do need to keep that project up to date - for example I'd say "mozilla" is a better guess on linux than "netscape" now.  Is the mac code still current even?

This really should belong in the JVM - platform specific java code like this is ugly and not what Java should be.

Thanks all for your help,

Will.

Offline tortoise

Junior Member




<3 Shmups


« Reply #8 - Posted 2003-10-26 02:45:05 »

I don't see how it could possibly be in the JVM. For it to be in the JVM it'd have to offer at least decent success rate, preferably be 100% reliable. On Unix, especially Linux, there's just no way. Unless Unix JVM's prompted for a browser upon installation, even that has problems. Probably the one browser to be installed on more Linux boxes than anything is Lynx, woo.

Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #9 - Posted 2003-10-26 05:32:54 »

well the JVM could search for common browsers such as netscape, mozilla in a "best effort" way, and could always return false if it failed.  The good reasons for having it in the JVM is that the developer wouldn't need to keep track of all the different operating systems that Java runs on nor keep it updated.  Apple would be able to code a specific Mac one for example, and if Mac OS XI comes out with a different browser config it wouldn't matter because the JVM for that OS would be updated.

It couldn't be perfect, I agree but it would certainly be better.

Will.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jens

Senior Member




Java for games!


« Reply #10 - Posted 2003-10-26 06:58:32 »

A browserlauncher has to take care of a lot of things. Checking the $BROWSER variable first may always be a good idea (it's not set up on many systems, but it gives the user a chance to specify the default browser). I don't know if there are other ways to find out a user's favourite browser (maybe you have to check first if the user runs KDE, Gnome or whatever). After you have done this you can try looking for global preferences, but this is dangerous, because the user's personal preferences may be different than root's preferences. Debian uses /etc/alternatives for this, but other distributions probably don't have a concept for this.

Another way is to check the mailcap files. First you read in $HOME/.mailcap and $HOME/.mailcap.order. If these files don't exist or don't contain handlers for text/html you read /etc/.mailcap and /etc/.mailcap.order. You can start whichever browser comes first in /etc/.mailcap or is specified in /etc/.mailcap.order. /etc/.mailcap should contain most of the browser's on the user's system, so you may read them all in and let the user of your app choose which one to use.

Another thing you have to take care for is if you really want a text based browser. If you know that the pages you want to show can't be displayed in a text based browser very well, you may choose a graphical browser, although a text based browser is the default.

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline sma

Junior Member





« Reply #11 - Posted 2003-10-26 08:06:49 »

If SWT is an option, they have a Program class which knows how to start a program associated as a viewer for a given document. This is, you'd simply do a Program.launch("file.html"); and let the system worry about the details.

.: Truth Until Paradox!
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #12 - Posted 2003-10-26 20:17:16 »

Quote
cas, so browserlauncher will work in all versions of Windows will it?

My only question is why they would use "rundll32 url.dll,FileProtocolHandler" and not just "start"?

I think you meant to address me Smiley
'start' is an executable program on win95/98, but on NT it is built in to the shell so can't be "exec'd" directly like that.

I agree about keeping it up to date - but hey it's open source - if you have updates pass them on.  (I agree re: Mozilla vs. Netscape.. but Opera is also a significant choice for Linux)

Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #13 - Posted 2003-10-26 22:11:17 »

Quote

I think you meant to address me Smiley


Well both of you actually, Cas did mention that it was what he used and I figured he may have done a fair bit of testing (being a commercial app).

Quote

'start' is an executable program on win95/98, but on NT it is built in to the shell so can't be "exec'd" directly like that.


Thanks for clearing that up Smiley

Quote

I agree about keeping it up to date - but hey it's open source - if you have updates pass them on.  (I agree re: Mozilla vs. Netscape.. but Opera is also a significant choice for Linux)


Yeah, call me lazy but I was hoping to have a pre-packaged solution (surely an up to date one must exist?).  But it looks like taking the browserlauncher code will be a good start (and for sure I shall send them any improvements...)

Maintaining a platform-specific browser launch code was exactally what I was trying to avoid when I asked this question - I don't want to have to update these particular programs every year or so when the world's browsers change Sad  That is obviously a dream but failing that simply updaing my package with the updated jar of a well maintained browser launch package would also be nice Smiley

Will.

Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #14 - Posted 2003-10-26 22:13:12 »

Quote
If SWT is an option, they have a Program class which knows how to start a program associated as a viewer for a given document. This is, you'd simply do a Program.launch("file.html"); and let the system worry about the details.


SWT is not an option but it looks like they have thought about this issue very well Smiley

Thanks,

Will.

Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #15 - Posted 2003-10-26 22:18:32 »

Quote
A browserlauncher has to take care of a lot of things. Checking the $BROWSER variable first may always be a good idea (it's not set up on many systems, but it gives the user a chance to specify the default browser). I don't know if there are other ways to find out a user's favourite browser (maybe you have to check first if the user runs KDE, Gnome or whatever). After you have done this you can try looking for global preferences, but this is dangerous, because the user's personal preferences may be different than root's preferences. Debian uses /etc/alternatives for this, but other distributions probably don't have a concept for this.

Another way is to check the mailcap files. First you read in $HOME/.mailcap and $HOME/.mailcap.order. If these files don't exist or don't contain handlers for text/html you read /etc/.mailcap and /etc/.mailcap.order. You can start whichever browser comes first in /etc/.mailcap or is specified in /etc/.mailcap.order. /etc/.mailcap should contain most of the browser's on the user's system, so you may read them all in and let the user of your app choose which one to use.

Another thing you have to take care for is if you really want a text based browser. If you know that the pages you want to show can't be displayed in a text based browser very well, you may choose a graphical browser, although a text based browser is the default.


linx being default could be a problem, however I'm guessing most people who have linx set as default have done it for a very good reason (it's a great browser, I do love it's simplicity but I don't think I would ever make it my default).  Unfortunatally you can't even count on linx being present these days.

Thank you for the excellent tips - if I go down the road of modifying the browserlauncher code I shall definitally use them.

I was going to submit a bug about the mozilla/netscape thing but look at the bug list:
http://sourceforge.net/tracker/?atid=114506&group_id=14506&func=browse

Will.

Offline tortoise

Junior Member




<3 Shmups


« Reply #16 - Posted 2003-10-27 01:34:44 »

Uhh, you can't count on anything being present these days, you never could with Linux. Even more "formalized" Unices don't offer many promises.

DistroWatch alone counts 100 Linux distros, most distros have multiple versions, there's at least 10 browsers available for Linux, and Linux users can and do change their system as they please. There's no central authority over Linux, it's literally a very loose collection of programs sitting on top of a common kernel. At best this is a very difficult problem to solve for Linux, and at worst it's impossible.
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #17 - Posted 2003-10-27 22:47:26 »

Well I think you could design a JVM which would have a pretty good stab at finding one graphical browser on the system and I would not say it's impossible at all.  Not that it matters since it probably will not happen anyway.

Sounds like the the browser launcher code is the best we have.

Let me ask - if I manage to get in contact with the developer of it, is anyone else here interested in perhaps joining the sourceforge project and updating it a bit (or failing that since, it's been five years since it was updated and it's open source we can always branch off a new project).

Will.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (48 views)
2014-04-15 18:08:23

BurntPizza (44 views)
2014-04-15 03:46:01

UprightPath (60 views)
2014-04-14 17:39:50

UprightPath (42 views)
2014-04-14 17:35:47

Porlus (58 views)
2014-04-14 15:48:38

tom_mai78101 (81 views)
2014-04-10 04:04:31

BurntPizza (140 views)
2014-04-08 23:06:04

tom_mai78101 (240 views)
2014-04-05 13:34:39

trollwarrior1 (200 views)
2014-04-04 12:06:45

CJLetsGame (207 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!