Function: browse-url

browse-url is an autoloaded, interactive and byte-compiled function defined in browse-url.el.gz.

Signature

(browse-url URL &rest ARGS)

Documentation

Open URL using a configurable method.

This will typically (by default) open URL with an external web browser, but a wide variety of different methods can be used, depending on the URL type.

The variables browse-url-browser-function, browse-url-handlers, and browse-url-default-handlers determine which browser function to use.

This command prompts for a URL, defaulting to the URL at or before point.

The additional ARGS are passed to the browser function. See the doc strings of the actual functions, starting with browse-url-browser-function, for information about the significance of ARGS (most of the functions ignore it).

If ARGS are omitted, the default is to pass browse-url-new-window-flag as ARGS.

Probably introduced at or before Emacs version 19.31.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/net/browse-url.el.gz
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Browser-independent commands

;; A generic command to call the current browse-url-browser-function

;;;###autoload
(defun browse-url (url &rest args)
  "Open URL using a configurable method.
This will typically (by default) open URL with an external web
browser, but a wide variety of different methods can be used,
depending on the URL type.

The variables `browse-url-browser-function',
`browse-url-handlers', and `browse-url-default-handlers'
determine which browser function to use.

This command prompts for a URL, defaulting to the URL at or
before point.

The additional ARGS are passed to the browser function.  See the
doc strings of the actual functions, starting with
`browse-url-browser-function', for information about the
significance of ARGS (most of the functions ignore it).

If ARGS are omitted, the default is to pass
`browse-url-new-window-flag' as ARGS."
  (interactive (browse-url-interactive-arg "URL: "))
  (unless (called-interactively-p 'interactive)
    (setq args (or args (list browse-url-new-window-flag))))
  (when (and url-handler-mode
             (not (file-name-absolute-p url))
             (not (string-match "\\`[a-z]+:" url)))
    (setq url (expand-file-name url)))
  (let ((process-environment (copy-sequence process-environment))
	(function (or (browse-url-select-handler url)
                      browse-url-browser-function))
	;; Ensure that `default-directory' exists and is readable (bug#6077).
	(default-directory (or (unhandled-file-name-directory default-directory)
			       (expand-file-name "~/"))))
    ;; When connected to various displays, be careful to use the display of
    ;; the currently selected frame, rather than the original start display,
    ;; which may not even exist any more.
    (if (stringp (frame-parameter nil 'display))
        (setenv "DISPLAY" (frame-parameter nil 'display)))
    (if (functionp function)
        (apply function url args)
      (error "No suitable browser for URL %s" url))))