5 Send URL: Opening a Web Browser
(require net/sendurl) | package: net-lib |
See also browser/external, which requires racket/gui, but can prompt the user for a browser if no browser preference is set.
procedure
(send-url str [ separate-window? #:escape? escape?]) → void? str : string? separate-window? : any/c = #t escape? : any/c = #t
If escape? is true, then str is escaped (by UTF-8 encoding followed by “%” encoding) to avoid dangerous shell characters: single quotes, double quotes, backquotes, dollar signs, backslashes, non-ASCII characters, and non-graphic characters. Note that escaping does not affect already-encoded characters in str.
There are two ways to override the above behavior: the external-browser parameter and the 'external-browser preference. A valid setting for both the external-browser parameter and the 'external-browser preference must satisfy browser-preference?, with a restriction that the setting for the 'external-browser preference cannot be a procedure. The external-browser parameter takes priority over 'external-browser preference: the preference is only used when (external-browser) is #f. See put-preferences for details on setting preferences.
On Unix, it’s recommended to not override the default behavior, but to rely on xdg-open in browser-list.
procedure
(send-url/file path [ separate-window? #:fragment fragment #:query query]) → void? path : path-string? separate-window? : any/c = #t fragment : (or/c string? #f) = #f query : (or/c string? #f) = #f
The path, fragment, and query arguments are all encoded in the same way as a path provided to send-url, which means that already-encoded characters are used as-is.
procedure
(send-url/contents contents [ separate-window? #:fragment fragment #:query query #:delete-at seconds]) → void? contents : string? separate-window? : any/c = #t fragment : (or/c string? #f) = #f query : (or/c string? #f) = #f seconds : (or/c number? #f) = #f
When send-url/contents is called, it scans old generated files (this happens randomly, not on every call) and removes them to avoid cluttering the temporary directory. If the seconds argument is a number, then the temporary file is more eagerly removed after the specified number of seconds; the deletion happens in a thread, so if Racket exits earlier, the deletion will not happen. If the seconds argument is #f, no eager deletion happens, but old temporary files are still deleted as described above.
procedure
(send-url/mac url [#:browser browser]) → void?
url : string? browser : (or/c string? #f) = #f
(send-url/mac "https://www.google.com/" #:browser "Firefox")
parameter
(external-browser cmd) → void? cmd : browser-preference?
procedure
(browser-preference? a) → boolean?
a : any/c
The value #f, which falls back to the next preference method.
A procedure? that accepts a URL string. This value is not allowed for the 'external-browser preference.
A symbol in browser-list that indicates a browser to use.
A pair of strings to be concatenated with a URL string to form a shell command to run. The first string is the command prefix and the second string is the command suffix. This method requires extra care:
The URL can hold characters like #, ?, and &, so the pair of strings should place double quotes around the URL.
The URL should be encoded to make it work inside shell double-quotes, so the default value of escape? in send-url should be used.
value
Added in version 7.5.0.10 of package net-lib.
value
NOTE: This value is deprecated; use browser-list, instead.
The same as browser-list.
Changed in version 7.5.0.10 of package net-lib: Changed the value to be an alias of browser-list.