This page describes how to call upon an external [browser] to display a page, given the URL. - DL It also discussed how to do other things with browsers, such as the opposite (what page is the browser currently viewing?). Why doesn't someone put the 'best of breed' into [tklib]? ---- I use this on [Windows] 95 and 98. proc url x { set x [regsub -all -nocase {htm} $x {ht%6D}] exec rundll32 url.dll,FileProtocolHandler $x & } Internet Explorer doesn't like .htm [http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&safe=off&th=3b125e7bc35a509a&rnum=5] [http://www.jsifaq.com/SUBI/tip4100/rh4162.htm] that's why I work around it. ''--[ro]'' Thanks [Vince] for suggesting the [rundll] method ;) I found the htm problem the hard way ;( ---- There was a potential problem with embedded spaces in the path in the unix branch. 'auto_execok' returns a list, but I assume that the value of $::env(BROWSER) should be a simple string. I've changed the code to reflect that assumption, but it may cause trouble in the unlikely event that 'auto_execok' actually returns a list of length greater than 1. - DGP The windows branch can be simplified in Tcl interpreters of release 8.3 or later. The command [eval exec [auto_execok start] [list $url]] should launch the browser on both NT and 95/98. -DGP '''NOTE''': The following code example '''will not work''' in Tcl releases 8.1 and later, due to Tcl Bug 219372 "'''Cannot set env array element via upvar #0'''" [https://sourceforge.net/tracker/index.php?func=detail&aid=219372&group_id=10894&atid=110894]. -- '''DGP''' proc browser::findExecutable {progname varname} { upvar 1 $varname result set progs [auto_execok $progname] if {[llength $progs]} { set result [lindex $progs 0] } return [llength $progs] } proc browser::urlOpen {url} { global env tcl_platform switch $tcl_platform(platform) { "unix" { expr { [info exists env(BROWSER)] || [findExecutable netscape env(BROWSER)] || [findExecutable iexplorer env(BROWSER)] || [findExecutable $env(NETSCAPE) env(BROWSER)] || [findExecutable lynx env(BROWSER)] } # lynx can also output formatted text to a variable # with the -dump option, as a last resort: # set formatted_text [ exec lynx -dump $url ] - PSE if {[catch {exec $env(BROWSER) -remote $url}]} { # perhaps browser doesn't understand -remote flag if {[catch {exec $env(BROWSER) $url &} emsg]} { error "Error displaying $url in browser\n$emsg" # Another possibility is to just pop a window up # with the URL to visit in it. - DKF } } } "windows" { if {$tcl_platform(os) == "Windows NT"} { set rc [catch {exec $env(COMSPEC) /c start $url &} emsg] } else { # Windows 95/98 set rc [catch {exec start $url} emsg] } if {$rc} { error "Error displaying $url in browser\n$emsg" } } "macintosh" { if {0 == [info exists env(BROWSER)]} { set env(BROWSER) "Browse the Internet" } if {[catch { AppleScript execute\ "tell application \"$env(BROWSER)\" open url \"$url\" end tell "} emsg] } then { error "Error displaying $url in browser\n$emsg" } } } ;## end of switch } Fixed two things in Windows NT section: changed tcl_platform to ::tcl_platform and added & to end of cmd.exe invocation. Now it works on NT. Tero Here's an example from my Tcl/Tk Programmer's Reference [http://www.purl.org/net/TclTkProgRef] which uses the registry on Win32. This example can browse to URLs with anchors (foo.html#bar). It can be adapted to open any file based on it's association by replacing ".html" with the desired extention in the first registry get command. (perSub does percent substitutions like those in event bindings. It's available in the regexp example at the site noted above.) Chris Nelson package require registry proc showHtml { htmlFile } { # Look for the application under # HKEY_CLASSES_ROOT set root HKEY_CLASSES_ROOT # Get the application key for HTML files set appKey [registry get $root\\.html ""] # Get the command for opening HTML files set appCmd [registry get \ $root\\$appKey\\shell\\open\\command ""] # Substitute the HTML filename into the # command for %1 set appCmd [perSub $appCmd %1 $htmlFile] # Double up the backslashes for eval (below) regsub -all {\\} $appCmd {\\\\} appCmd # Invoke the command eval exec $appCmd & } showHtml C:/foobar.html Surely the line set result [lindex $progs] in browser::findExecutable should be set result [list $progs] BHT We verified this to work on a variety of Windows platforms: # On Win95, even if there is a web browser installed, it cannot # open an internet address, only a local .html file. # Win98 doesn't like "/" if {[lindex [array get ::tcl_platform] 1]=="4.10"} { regsub -all "/" $file "\\\\" file } # Substitute & with ^& # (Example: http://www.ideogramic.com?a=1&b=1 => http://www.ideogramic.com?a=1^&b=1 # Otherwise, it will only open http://www.ideogramic.com?a=1) regsub -all "&" $file "^&" file # Open file eval exec [auto_execok start] [list $file] & Trust me :-) Klaus Marius Hansen [Brian Theado] 13May03 - How does the ^& trick work? Is it something within Tcl that is treating the ^ as an escape? If I try eval exec [auto_execok start] [list http://ats.nist.gov/cgi-bin/cgi.tcl/echo.cgi?hello=1&hi=2] I get 'hi' is not recognized as an internal or external command, operable program or batch file. and ''hi=2'' doesn't make it through to the browser. If I try: eval exec [auto_execok start] [list http://ats.nist.gov/cgi-bin/cgi.tcl/echo.cgi?hello=1^&hi=2] Both ''hello=1'' and ''hi=2'' makes it through to the browser. This happens for me on both WinXP and NT 4.0. [BR] 15May03 - On NT, START is an internal command to CMD.EXE. ^ is an escape in CMD.EXE command syntax. You can do line continuation with ^, and you can do several commands in one line with &. You use ^^ and ^& if you really want to pass ^ or & to a command. You can also quote using double quotation marks as in eval exec [auto_execok start] {"http://ats.nist.gov/cgi-bin/cgi.tcl/echo.cgi?hello=1&hi=2"} All this is probably different on W9x/Me where START.EXE is an external command and the command interpreter is different (COMMAND.COM). [MG] April 1st 2004 - On Win 98SE, at least, the '^' isn't needed; including it causes 'hello' to equal '1^' rather than just '1' on the webpage. ---- For UNIX users that want to use ONE Netscape window to display various content, here's what I do: Create a default html file that establishes an initial title for the Netscape window that starts.