Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Link to Website.
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
yumrum




PostPosted: Thu May 20, 2010 7:43 pm   Post subject: Link to Website.

I was wondering if there is a way to make my button when clicked open up a browser on a specific website?
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Thu May 20, 2010 7:44 pm   Post subject: RE:Link to Website.

If you use Sys.Exec ( "url-goes-here" ) you should be able to open a website in the user's default browser. You'll have to put that in the callbacks you specify for the button.
DtY




PostPosted: Thu May 20, 2010 8:29 pm   Post subject: Re: RE:Link to Website.

DemonWasp @ Thu May 20, 2010 7:44 pm wrote:
If you use Sys.Exec ( "url-goes-here" ) you should be able to open a website in the user's default browser. You'll have to put that in the callbacks you specify for the button.
Just want to point out, this will only work on windows.

On Mac OS X, the same thing can be accomplished with Sys.Exec("open url-goes-here"), on Linux or other Unices, you need to run a specific browser, firefox is pretty universal, but if you want to be more universal, you can have an option, or look in an environment variable. To open a webpage in firefox, you can do Sys.Exec("firefox url-goes-here").

---

The reason this only works on windows is that Sys.Exec() will execute a shell command, which on Windows can be any file, which also includes urls, which will open in the default program. This does not work anywhere else, but on Mac OS X, there is the `open` command, which will open a file in the default application (like just entering a filename in Windows). Linux and other Unices generally have no idea of "default applications", so you have to give an explicit command (in this case, firefox), followed by the file to open with it.

Most desktop environments on Linux (like KDE and Gnome) do keep track of default applications, so there should be some way to open with the default web browser if you can assume a certain desktop environment.

---

Non of this matters if you only need it to work on Windows.
yumrum




PostPosted: Fri May 21, 2010 8:32 pm   Post subject: RE:Link to Website.

Fortunately i got windows so I'm all good. Thank you.
That stuff on the other operating systems is actually really cool.
yumrum




PostPosted: Tue May 25, 2010 7:23 pm   Post subject: RE:Link to Website.

U trued Getting the Sys.Exec(Url) to work but i'm am getting an error that the variable Sys dosn't exsist.
Tony




PostPosted: Wed May 26, 2010 11:09 am   Post subject: RE:Link to Website.

Sys.Exec
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
TheGuardian001




PostPosted: Wed May 26, 2010 12:02 pm   Post subject: Re: Link to Website.

I'm guessing nobody here has realised that this post actually isn't in the Turing section of the forums?
Tony




PostPosted: Wed May 26, 2010 12:10 pm   Post subject: RE:Link to Website.

Oh yeah... hah.

Runtime.exec(); perhaps?

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html#exec%28java.lang.String%29
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: