Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to goto URL from app



I'd like to second this answer as it only uses Sun APIs.

md


On Tuesday, July 8, 2003, at 10:09 AM, Nick Howes wrote:

On Monday, July 7, 2003, at 11:00 PM, jason rusoff <email@hidden> wrote:

Date: Mon, 7 Jul 2003 21:23:22 -0700
Subject: How to goto URL from app?
From: jason rusoff <email@hidden>
To: email@hidden

I have a Cocoa/Java app and I'm trying to open a particular web site
when a user hits a button. I'd like it to launch whatever the default
web browser is and go to the site. I know that applets can invoke
AppletContext.showDocument to do this. Is there a way to do this from
an app?
My app descends from NSApplication, so I don't think I can assume it's
an applet and use showDocument. Any tips?

I spent quite a bit of time trying to get this to work for my (pure Java) app. Here's what I ended up with, it seems to work OK for the http:, file: and mailto: protocols.

public static void openURL(String s) throws Exception {
String[] params;
switch (os) {
case OS_MAC :
params = new String[] {
"open",
escapeURLString(s)
};
break;
case OS_WIN_9X :
params = new String[] {
"command.com",
"/c",
"start",
'"' + s + '"'
};
break;
case OS_WIN_NT :
params = new String[] {
"cmd.exe",
"/c",
"start",
"\"\"",
'"' + s + '"'
};
break;
default : //try netscape on other platforms
params = new String[] {
"netscape",
"-remote",
"'openURL(" + s + ")'"
};
break;
}
Process process = Runtime.getRuntime().exec(params);
process.waitFor();
process.exitValue();
}

escapeURLString() just replaces spaces with %20

Hope that helps, Nick
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: How to goto URL from app (From: Nick Howes <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.