cpython/Doc/library/webbrowser.rst

209 lines
8.9 KiB
ReStructuredText
Raw Normal View History

2007-08-15 11:28:01 -03:00
:mod:`webbrowser` --- Convenient Web-browser controller
=======================================================
.. module:: webbrowser
:synopsis: Easy-to-use controller for Web browsers.
.. moduleauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
The :mod:`webbrowser` module provides a high-level interface to allow displaying
Web-based documents to users. Under most circumstances, simply calling the
:func:`.open` function from this module will do the right thing.
2007-08-15 11:28:01 -03:00
Under Unix, graphical browsers are preferred under X11, but text-mode browsers
will be used if graphical browsers are not available or an X11 display isn't
available. If text-mode browsers are used, the calling process will block until
the user exits the browser.
If the environment variable :envvar:`BROWSER` exists, it is interpreted to
override the platform default list of browsers, as a :data:`os.pathsep`-separated
list of browsers to try in order. When the value of a list part contains the
string ``%s``, then it is interpreted as a literal browser command line to be
used with the argument URL substituted for ``%s``; if the part does not contain
Merged revisions 72319-72320,72467,72661,72675-72679,72703,72708,72710,72712,72801-72802,72820,72822,72824,72826-72828,72830 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r72319 | georg.brandl | 2009-05-05 10:28:49 +0200 (Di, 05 Mai 2009) | 1 line #1309567: fix linecache behavior of stripping subdirectories from paths when looking for relative filename matches. Also add a linecache test suite. ........ r72320 | georg.brandl | 2009-05-05 10:30:28 +0200 (Di, 05 Mai 2009) | 1 line Add a news entry for r72319. ........ r72467 | georg.brandl | 2009-05-08 14:17:34 +0200 (Fr, 08 Mai 2009) | 1 line Fix name. ........ r72661 | georg.brandl | 2009-05-15 10:03:03 +0200 (Fr, 15 Mai 2009) | 1 line Fix example output for doctest-like demos. ........ r72675 | georg.brandl | 2009-05-16 13:13:21 +0200 (Sa, 16 Mai 2009) | 1 line #6034: clarify __reversed__ doc. ........ r72676 | georg.brandl | 2009-05-16 13:14:46 +0200 (Sa, 16 Mai 2009) | 1 line #6025: fix signature of parse(). ........ r72677 | georg.brandl | 2009-05-16 13:18:55 +0200 (Sa, 16 Mai 2009) | 1 line #6009: undocument default argument of Option as deprecated. ........ r72678 | georg.brandl | 2009-05-16 13:21:29 +0200 (Sa, 16 Mai 2009) | 1 line #2856: document 2.x os.listdir() behavior for undecodable filenames. ........ r72679 | georg.brandl | 2009-05-16 13:24:41 +0200 (Sa, 16 Mai 2009) | 1 line Fix about and bugs pages to match real workflow. ........ r72703 | georg.brandl | 2009-05-17 10:10:27 +0200 (So, 17 Mai 2009) | 1 line part of #4144: fix exception message in console session. ........ r72708 | georg.brandl | 2009-05-17 10:24:29 +0200 (So, 17 Mai 2009) | 1 line #6017: better document behavior of dictiterators when the dict is changed. ........ r72710 | georg.brandl | 2009-05-17 10:36:04 +0200 (So, 17 Mai 2009) | 1 line #5942: Copy over flag table from dbm.rst which is clearer. ........ r72712 | georg.brandl | 2009-05-17 10:55:00 +0200 (So, 17 Mai 2009) | 1 line #5935: mention that BROWSER is looked for in PATH. ........ r72801 | georg.brandl | 2009-05-20 20:31:14 +0200 (Mi, 20 Mai 2009) | 1 line #6055: refer to "sqlite3" consistently. ........ r72802 | georg.brandl | 2009-05-20 20:35:27 +0200 (Mi, 20 Mai 2009) | 1 line #6051: refer to email examples for better way to construct email messages. ........ r72820 | georg.brandl | 2009-05-22 09:23:32 +0200 (Fr, 22 Mai 2009) | 1 line Use raise X(y). ........ r72822 | georg.brandl | 2009-05-22 11:33:25 +0200 (Fr, 22 Mai 2009) | 1 line #6084: fix example. ........ r72824 | georg.brandl | 2009-05-22 11:43:17 +0200 (Fr, 22 Mai 2009) | 1 line Fix references to file-related functions and methods (os.* vs file.*). ........ r72826 | georg.brandl | 2009-05-22 11:49:42 +0200 (Fr, 22 Mai 2009) | 1 line Fix confusing wording. ........ r72827 | georg.brandl | 2009-05-22 11:50:30 +0200 (Fr, 22 Mai 2009) | 1 line s/use/call/ ........ r72828 | georg.brandl | 2009-05-22 11:58:48 +0200 (Fr, 22 Mai 2009) | 1 line Correction in softspace behavior description. ........ r72830 | georg.brandl | 2009-05-22 12:40:00 +0200 (Fr, 22 Mai 2009) | 1 line #6086: fix spelling and use a better exception to catch. ........
2009-05-26 06:04:23 -03:00
``%s``, it is simply interpreted as the name of the browser to launch. [1]_
2007-08-15 11:28:01 -03:00
For non-Unix platforms, or when a remote browser is available on Unix, the
controlling process will not wait for the user to finish with the browser, but
allow the remote browser to maintain its own windows on the display. If remote
browsers are not available on Unix, the controlling process will launch a new
browser and wait.
The script :program:`webbrowser` can be used as a command-line interface for the
module. It accepts an URL as the argument. It accepts the following optional
parameters: :option:`-n` opens the URL in a new browser window, if possible;
:option:`-t` opens the URL in a new browser page ("tab"). The options are,
naturally, mutually exclusive.
The following exception is defined:
.. exception:: Error
Exception raised when a browser control error occurs.
The following functions are defined:
Merged revisions 74008,74021-74022,74074-74075,74077,74148,74179,74188,74192-74194,74200,74205 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r74008 | benjamin.peterson | 2009-07-15 02:46:42 +0200 (Mi, 15 Jul 2009) | 1 line update year ........ r74021 | georg.brandl | 2009-07-16 09:33:04 +0200 (Do, 16 Jul 2009) | 1 line #6486: start with built in functions rather than "built in objects". ........ r74022 | georg.brandl | 2009-07-16 09:38:35 +0200 (Do, 16 Jul 2009) | 1 line #6481: fix typo in os.system() replacement. ........ r74074 | georg.brandl | 2009-07-18 11:03:10 +0200 (Sa, 18 Jul 2009) | 1 line #6513: fix example code: warning categories are classes, not instances. ........ r74075 | georg.brandl | 2009-07-18 11:06:31 +0200 (Sa, 18 Jul 2009) | 1 line #6505: fix typos. ........ r74077 | georg.brandl | 2009-07-18 11:43:40 +0200 (Sa, 18 Jul 2009) | 1 line #6489: fix an ambiguity in getiterator() documentation. ........ r74148 | ezio.melotti | 2009-07-21 22:18:27 +0200 (Di, 21 Jul 2009) | 1 line #6536 fixed typo ........ r74179 | ezio.melotti | 2009-07-22 23:08:49 +0200 (Mi, 22 Jul 2009) | 1 line #6423 has_key -> in ........ r74188 | benjamin.peterson | 2009-07-23 16:25:31 +0200 (Do, 23 Jul 2009) | 1 line use bools ........ r74192 | georg.brandl | 2009-07-24 18:28:38 +0200 (Fr, 24 Jul 2009) | 1 line Fix arg types of et#. ........ r74193 | georg.brandl | 2009-07-24 18:46:38 +0200 (Fr, 24 Jul 2009) | 1 line Dont put "void" in signature for nullary functions. ........ r74194 | georg.brandl | 2009-07-24 22:09:46 +0200 (Fr, 24 Jul 2009) | 1 line #6564: fix section about the two raise syntaxes. ........ r74200 | georg.brandl | 2009-07-25 15:02:15 +0200 (Sa, 25 Jul 2009) | 1 line #6571: add index entries for more operators. ........ r74205 | georg.brandl | 2009-07-26 15:36:39 +0200 (So, 26 Jul 2009) | 1 line #6576: fix cross-refs in re docs. ........
2009-10-27 11:34:21 -03:00
.. function:: open(url[, new=0[, autoraise=True]])
2007-08-15 11:28:01 -03:00
Merged revisions 74008,74021-74022,74074-74075,74077,74148,74179,74188,74192-74194,74200,74205 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r74008 | benjamin.peterson | 2009-07-15 02:46:42 +0200 (Mi, 15 Jul 2009) | 1 line update year ........ r74021 | georg.brandl | 2009-07-16 09:33:04 +0200 (Do, 16 Jul 2009) | 1 line #6486: start with built in functions rather than "built in objects". ........ r74022 | georg.brandl | 2009-07-16 09:38:35 +0200 (Do, 16 Jul 2009) | 1 line #6481: fix typo in os.system() replacement. ........ r74074 | georg.brandl | 2009-07-18 11:03:10 +0200 (Sa, 18 Jul 2009) | 1 line #6513: fix example code: warning categories are classes, not instances. ........ r74075 | georg.brandl | 2009-07-18 11:06:31 +0200 (Sa, 18 Jul 2009) | 1 line #6505: fix typos. ........ r74077 | georg.brandl | 2009-07-18 11:43:40 +0200 (Sa, 18 Jul 2009) | 1 line #6489: fix an ambiguity in getiterator() documentation. ........ r74148 | ezio.melotti | 2009-07-21 22:18:27 +0200 (Di, 21 Jul 2009) | 1 line #6536 fixed typo ........ r74179 | ezio.melotti | 2009-07-22 23:08:49 +0200 (Mi, 22 Jul 2009) | 1 line #6423 has_key -> in ........ r74188 | benjamin.peterson | 2009-07-23 16:25:31 +0200 (Do, 23 Jul 2009) | 1 line use bools ........ r74192 | georg.brandl | 2009-07-24 18:28:38 +0200 (Fr, 24 Jul 2009) | 1 line Fix arg types of et#. ........ r74193 | georg.brandl | 2009-07-24 18:46:38 +0200 (Fr, 24 Jul 2009) | 1 line Dont put "void" in signature for nullary functions. ........ r74194 | georg.brandl | 2009-07-24 22:09:46 +0200 (Fr, 24 Jul 2009) | 1 line #6564: fix section about the two raise syntaxes. ........ r74200 | georg.brandl | 2009-07-25 15:02:15 +0200 (Sa, 25 Jul 2009) | 1 line #6571: add index entries for more operators. ........ r74205 | georg.brandl | 2009-07-26 15:36:39 +0200 (So, 26 Jul 2009) | 1 line #6576: fix cross-refs in re docs. ........
2009-10-27 11:34:21 -03:00
Display *url* using the default browser. If *new* is 0, the *url* is opened
in the same browser window if possible. If *new* is 1, a new browser window
is opened if possible. If *new* is 2, a new browser page ("tab") is opened
if possible. If *autoraise* is ``True``, the window is raised if possible
(note that under many window managers this will occur regardless of the
setting of this variable).
2007-08-15 11:28:01 -03:00
Merged revisions 71058,71149-71150,71212,71214-71216,71222,71225,71234,71237-71238,71240-71241,71243,71249,71251 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r71058 | georg.brandl | 2009-04-02 20:09:04 +0200 (Do, 02 Apr 2009) | 3 lines PyErr_NormalizeException may not set an error, so convert the PyErr_SetObject call on hitting the recursion limit into just assigning it to the arguments provided. ........ r71149 | georg.brandl | 2009-04-04 15:42:39 +0200 (Sa, 04 Apr 2009) | 1 line #5642: clarify map() compatibility to the builtin. ........ r71150 | georg.brandl | 2009-04-04 15:45:49 +0200 (Sa, 04 Apr 2009) | 1 line #5601: clarify that webbrowser is not meant for file names. ........ r71212 | georg.brandl | 2009-04-05 12:24:20 +0200 (So, 05 Apr 2009) | 1 line #1742837: expand HTTP server docs, and fix SocketServer ones to document methods as methods, not functions. ........ r71214 | georg.brandl | 2009-04-05 12:29:57 +0200 (So, 05 Apr 2009) | 1 line Normalize spelling of Mac OS X. ........ r71215 | georg.brandl | 2009-04-05 12:32:26 +0200 (So, 05 Apr 2009) | 1 line Avoid sure signs of a diseased mind. ........ r71216 | georg.brandl | 2009-04-05 12:41:02 +0200 (So, 05 Apr 2009) | 1 line #1718017: document the relation of os.path and the posixpath, ntpath etc. modules better. ........ r71222 | georg.brandl | 2009-04-05 13:07:14 +0200 (So, 05 Apr 2009) | 1 line #5615: make it possible to configure --without-threads again. ........ r71225 | georg.brandl | 2009-04-05 13:54:07 +0200 (So, 05 Apr 2009) | 1 line #5580: no need to use parentheses when converterr() argument is actually a type description. ........ r71234 | georg.brandl | 2009-04-05 15:16:35 +0200 (So, 05 Apr 2009) | 1 line Whitespace normalization. ........ r71237 | georg.brandl | 2009-04-05 16:24:52 +0200 (So, 05 Apr 2009) | 1 line #1326077: fix traceback formatting of SyntaxErrors. This fixes two differences with formatting coming from Python: a) the reproduction of location details in the error message if no line text is given, b) the prefixing of the last line by one space. ........ r71238 | georg.brandl | 2009-04-05 16:25:41 +0200 (So, 05 Apr 2009) | 1 line Add NEWS entry for r71237. ........ r71240 | georg.brandl | 2009-04-05 16:40:06 +0200 (So, 05 Apr 2009) | 1 line #5370: doc update about unpickling objects with custom __getattr__ etc. methods. ........ r71241 | georg.brandl | 2009-04-05 16:48:49 +0200 (So, 05 Apr 2009) | 1 line #5471: fix expanduser() for $HOME set to "/". ........ r71243 | georg.brandl | 2009-04-05 17:14:29 +0200 (So, 05 Apr 2009) | 1 line #5432: make plistlib docstring a raw string, since it contains examples with backslash escapes. ........ r71249 | georg.brandl | 2009-04-05 18:30:43 +0200 (So, 05 Apr 2009) | 1 line #5444: adapt make.bat to new htmlhelp output file name. ........ r71251 | georg.brandl | 2009-04-05 19:17:42 +0200 (So, 05 Apr 2009) | 1 line #5298: clarify docs about GIL by using more consistent wording. ........
2009-04-05 18:26:31 -03:00
Note that on some platforms, trying to open a filename using this function,
may work and start the operating system's associated program. However, this
is neither supported nor portable.
2007-08-15 11:28:01 -03:00
.. versionchanged:: 2.5
*new* can now be 2.
.. function:: open_new(url)
Open *url* in a new window of the default browser, if possible, otherwise, open
*url* in the only browser window.
.. function:: open_new_tab(url)
Open *url* in a new page ("tab") of the default browser, if possible, otherwise
equivalent to :func:`open_new`.
.. versionadded:: 2.5
.. function:: get([name])
Return a controller object for the browser type *name*. If *name* is empty,
return a controller for a default browser appropriate to the caller's
environment.
.. function:: register(name, constructor[, instance])
Register the browser type *name*. Once a browser type is registered, the
:func:`get` function can return a controller for that browser type. If
*instance* is not provided, or is ``None``, *constructor* will be called without
parameters to create an instance when needed. If *instance* is provided,
*constructor* will never be called, and may be ``None``.
This entry point is only useful if you plan to either set the :envvar:`BROWSER`
variable or call :func:`get` with a nonempty argument matching the name of a
handler you declare.
A number of browser types are predefined. This table gives the type names that
may be passed to the :func:`get` function and the corresponding instantiations
for the controller classes, all defined in this module.
+-----------------------+-----------------------------------------+-------+
| Type Name | Class Name | Notes |
+=======================+=========================================+=======+
| ``'mozilla'`` | :class:`Mozilla('mozilla')` | |
+-----------------------+-----------------------------------------+-------+
| ``'firefox'`` | :class:`Mozilla('mozilla')` | |
+-----------------------+-----------------------------------------+-------+
| ``'netscape'`` | :class:`Mozilla('netscape')` | |
+-----------------------+-----------------------------------------+-------+
| ``'galeon'`` | :class:`Galeon('galeon')` | |
+-----------------------+-----------------------------------------+-------+
| ``'epiphany'`` | :class:`Galeon('epiphany')` | |
+-----------------------+-----------------------------------------+-------+
| ``'skipstone'`` | :class:`BackgroundBrowser('skipstone')` | |
+-----------------------+-----------------------------------------+-------+
| ``'kfmclient'`` | :class:`Konqueror()` | \(1) |
+-----------------------+-----------------------------------------+-------+
| ``'konqueror'`` | :class:`Konqueror()` | \(1) |
+-----------------------+-----------------------------------------+-------+
| ``'kfm'`` | :class:`Konqueror()` | \(1) |
+-----------------------+-----------------------------------------+-------+
| ``'mosaic'`` | :class:`BackgroundBrowser('mosaic')` | |
+-----------------------+-----------------------------------------+-------+
| ``'opera'`` | :class:`Opera()` | |
+-----------------------+-----------------------------------------+-------+
| ``'grail'`` | :class:`Grail()` | |
+-----------------------+-----------------------------------------+-------+
| ``'links'`` | :class:`GenericBrowser('links')` | |
+-----------------------+-----------------------------------------+-------+
| ``'elinks'`` | :class:`Elinks('elinks')` | |
+-----------------------+-----------------------------------------+-------+
| ``'lynx'`` | :class:`GenericBrowser('lynx')` | |
+-----------------------+-----------------------------------------+-------+
| ``'w3m'`` | :class:`GenericBrowser('w3m')` | |
+-----------------------+-----------------------------------------+-------+
| ``'windows-default'`` | :class:`WindowsDefault` | \(2) |
+-----------------------+-----------------------------------------+-------+
| ``'internet-config'`` | :class:`InternetConfig` | \(3) |
+-----------------------+-----------------------------------------+-------+
| ``'macosx'`` | :class:`MacOSX('default')` | \(4) |
+-----------------------+-----------------------------------------+-------+
Notes:
(1)
"Konqueror" is the file manager for the KDE desktop environment for Unix, and
only makes sense to use if KDE is running. Some way of reliably detecting KDE
would be nice; the :envvar:`KDEDIR` variable is not sufficient. Note also that
the name "kfm" is used even when using the :program:`konqueror` command with KDE
2 --- the implementation selects the best strategy for running Konqueror.
(2)
Only on Windows platforms.
(3)
Only on Mac OS platforms; requires the standard MacPython :mod:`ic` module.
2007-08-15 11:28:01 -03:00
(4)
Only on Mac OS X platform.
2007-08-15 11:28:01 -03:00
Here are some simple examples::
url = 'http://www.python.org/'
2007-08-15 11:28:01 -03:00
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r68133 | antoine.pitrou | 2009-01-01 16:38:03 +0100 (Thu, 01 Jan 2009) | 1 line fill in actual issue number in tests ........ r68134 | hirokazu.yamamoto | 2009-01-01 16:45:39 +0100 (Thu, 01 Jan 2009) | 2 lines Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open file with `str' filename on Windows. ........ r68141 | benjamin.peterson | 2009-01-01 17:43:12 +0100 (Thu, 01 Jan 2009) | 1 line fix highlighting ........ r68142 | benjamin.peterson | 2009-01-01 18:29:49 +0100 (Thu, 01 Jan 2009) | 2 lines welcome to 2009, Python! ........ r68145 | amaury.forgeotdarc | 2009-01-02 01:03:54 +0100 (Fri, 02 Jan 2009) | 5 lines #4801 _collections module fails to build on cygwin. _PyObject_GC_TRACK is the macro version of PyObject_GC_Track, and according to documentation it should not be used for extension modules. ........ r68146 | ronald.oussoren | 2009-01-02 11:44:46 +0100 (Fri, 02 Jan 2009) | 2 lines Fix for issue4472: "configure --enable-shared doesn't work on OSX" ........ r68148 | ronald.oussoren | 2009-01-02 11:48:31 +0100 (Fri, 02 Jan 2009) | 2 lines Forgot to add a NEWS item in my previous checkin ........ r68149 | ronald.oussoren | 2009-01-02 11:50:48 +0100 (Fri, 02 Jan 2009) | 2 lines Fix for issue4780 ........ r68159 | ronald.oussoren | 2009-01-02 15:48:17 +0100 (Fri, 02 Jan 2009) | 2 lines Fix for issue 1627952 ........ r68160 | ronald.oussoren | 2009-01-02 15:52:09 +0100 (Fri, 02 Jan 2009) | 2 lines Fix for issue r1737832 ........ r68161 | ronald.oussoren | 2009-01-02 16:00:05 +0100 (Fri, 02 Jan 2009) | 3 lines Fix for issue 1149804 ........ r68162 | ronald.oussoren | 2009-01-02 16:06:00 +0100 (Fri, 02 Jan 2009) | 3 lines Fix for issue 4472 is incompatible with Cygwin, this patch should fix that. ........ r68166 | benjamin.peterson | 2009-01-02 19:26:23 +0100 (Fri, 02 Jan 2009) | 1 line document PyMemberDef ........ r68171 | georg.brandl | 2009-01-02 21:25:14 +0100 (Fri, 02 Jan 2009) | 3 lines #4811: fix markup glitches (mostly remains of the conversion), found by Gabriel Genellina. ........ r68172 | martin.v.loewis | 2009-01-02 21:32:55 +0100 (Fri, 02 Jan 2009) | 2 lines Issue #4075: Use OutputDebugStringW in Py_FatalError. ........ r68173 | martin.v.loewis | 2009-01-02 21:40:14 +0100 (Fri, 02 Jan 2009) | 2 lines Issue #4051: Prevent conflict of UNICODE macros in cPickle. ........ r68174 | benjamin.peterson | 2009-01-02 21:47:27 +0100 (Fri, 02 Jan 2009) | 1 line fix compilation on non-Windows platforms ........ r68179 | raymond.hettinger | 2009-01-02 22:26:45 +0100 (Fri, 02 Jan 2009) | 1 line Issue #4615. Document how to use itertools for de-duping. ........ r68195 | georg.brandl | 2009-01-03 14:45:15 +0100 (Sat, 03 Jan 2009) | 2 lines Remove useless string literal. ........ r68196 | georg.brandl | 2009-01-03 15:29:53 +0100 (Sat, 03 Jan 2009) | 2 lines Fix indentation. ........ r68210 | georg.brandl | 2009-01-03 20:10:12 +0100 (Sat, 03 Jan 2009) | 2 lines Set eol-style correctly for mp_distributing.py. ........ r68214 | georg.brandl | 2009-01-03 20:44:48 +0100 (Sat, 03 Jan 2009) | 2 lines Make indentation consistent. ........ r68215 | georg.brandl | 2009-01-03 21:15:14 +0100 (Sat, 03 Jan 2009) | 2 lines Fix role name. ........ r68217 | georg.brandl | 2009-01-03 21:30:15 +0100 (Sat, 03 Jan 2009) | 2 lines Add rstlint, a little tool to find subtle markup problems and inconsistencies in the Doc sources. ........ r68218 | georg.brandl | 2009-01-03 21:38:59 +0100 (Sat, 03 Jan 2009) | 2 lines Recognize usage of the default role. ........ r68219 | georg.brandl | 2009-01-03 21:47:01 +0100 (Sat, 03 Jan 2009) | 2 lines Fix uses of the default role. ........ r68220 | georg.brandl | 2009-01-03 21:55:06 +0100 (Sat, 03 Jan 2009) | 2 lines Remove trailing whitespace. ........ r68221 | georg.brandl | 2009-01-03 22:04:55 +0100 (Sat, 03 Jan 2009) | 2 lines Remove tabs from the documentation. ........ r68222 | georg.brandl | 2009-01-03 22:11:58 +0100 (Sat, 03 Jan 2009) | 2 lines Disable the line length checker by default. ........
2009-01-03 17:55:17 -04:00
# Open URL in a new tab, if a browser window is already open.
webbrowser.open_new_tab(url + 'doc/')
2007-08-15 11:28:01 -03:00
# Open URL in new window, raising the window if possible.
webbrowser.open_new(url)
.. _browser-controllers:
Browser Controller Objects
--------------------------
Browser controllers provide these methods which parallel three of the
module-level convenience functions:
2007-08-15 11:28:01 -03:00
.. method:: controller.open(url[, new=0[, autoraise=True]])
2007-08-15 11:28:01 -03:00
Display *url* using the browser handled by this controller. If *new* is 1, a new
browser window is opened if possible. If *new* is 2, a new browser page ("tab")
is opened if possible.
.. method:: controller.open_new(url)
Open *url* in a new window of the browser handled by this controller, if
possible, otherwise, open *url* in the only browser window. Alias
:func:`open_new`.
.. method:: controller.open_new_tab(url)
Open *url* in a new page ("tab") of the browser handled by this controller, if
possible, otherwise equivalent to :func:`open_new`.
.. versionadded:: 2.5
Merged revisions 72319-72320,72467,72661,72675-72679,72703,72708,72710,72712,72801-72802,72820,72822,72824,72826-72828,72830 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r72319 | georg.brandl | 2009-05-05 10:28:49 +0200 (Di, 05 Mai 2009) | 1 line #1309567: fix linecache behavior of stripping subdirectories from paths when looking for relative filename matches. Also add a linecache test suite. ........ r72320 | georg.brandl | 2009-05-05 10:30:28 +0200 (Di, 05 Mai 2009) | 1 line Add a news entry for r72319. ........ r72467 | georg.brandl | 2009-05-08 14:17:34 +0200 (Fr, 08 Mai 2009) | 1 line Fix name. ........ r72661 | georg.brandl | 2009-05-15 10:03:03 +0200 (Fr, 15 Mai 2009) | 1 line Fix example output for doctest-like demos. ........ r72675 | georg.brandl | 2009-05-16 13:13:21 +0200 (Sa, 16 Mai 2009) | 1 line #6034: clarify __reversed__ doc. ........ r72676 | georg.brandl | 2009-05-16 13:14:46 +0200 (Sa, 16 Mai 2009) | 1 line #6025: fix signature of parse(). ........ r72677 | georg.brandl | 2009-05-16 13:18:55 +0200 (Sa, 16 Mai 2009) | 1 line #6009: undocument default argument of Option as deprecated. ........ r72678 | georg.brandl | 2009-05-16 13:21:29 +0200 (Sa, 16 Mai 2009) | 1 line #2856: document 2.x os.listdir() behavior for undecodable filenames. ........ r72679 | georg.brandl | 2009-05-16 13:24:41 +0200 (Sa, 16 Mai 2009) | 1 line Fix about and bugs pages to match real workflow. ........ r72703 | georg.brandl | 2009-05-17 10:10:27 +0200 (So, 17 Mai 2009) | 1 line part of #4144: fix exception message in console session. ........ r72708 | georg.brandl | 2009-05-17 10:24:29 +0200 (So, 17 Mai 2009) | 1 line #6017: better document behavior of dictiterators when the dict is changed. ........ r72710 | georg.brandl | 2009-05-17 10:36:04 +0200 (So, 17 Mai 2009) | 1 line #5942: Copy over flag table from dbm.rst which is clearer. ........ r72712 | georg.brandl | 2009-05-17 10:55:00 +0200 (So, 17 Mai 2009) | 1 line #5935: mention that BROWSER is looked for in PATH. ........ r72801 | georg.brandl | 2009-05-20 20:31:14 +0200 (Mi, 20 Mai 2009) | 1 line #6055: refer to "sqlite3" consistently. ........ r72802 | georg.brandl | 2009-05-20 20:35:27 +0200 (Mi, 20 Mai 2009) | 1 line #6051: refer to email examples for better way to construct email messages. ........ r72820 | georg.brandl | 2009-05-22 09:23:32 +0200 (Fr, 22 Mai 2009) | 1 line Use raise X(y). ........ r72822 | georg.brandl | 2009-05-22 11:33:25 +0200 (Fr, 22 Mai 2009) | 1 line #6084: fix example. ........ r72824 | georg.brandl | 2009-05-22 11:43:17 +0200 (Fr, 22 Mai 2009) | 1 line Fix references to file-related functions and methods (os.* vs file.*). ........ r72826 | georg.brandl | 2009-05-22 11:49:42 +0200 (Fr, 22 Mai 2009) | 1 line Fix confusing wording. ........ r72827 | georg.brandl | 2009-05-22 11:50:30 +0200 (Fr, 22 Mai 2009) | 1 line s/use/call/ ........ r72828 | georg.brandl | 2009-05-22 11:58:48 +0200 (Fr, 22 Mai 2009) | 1 line Correction in softspace behavior description. ........ r72830 | georg.brandl | 2009-05-22 12:40:00 +0200 (Fr, 22 Mai 2009) | 1 line #6086: fix spelling and use a better exception to catch. ........
2009-05-26 06:04:23 -03:00
.. rubric:: Footnotes
.. [1] Executables named here without a full path will be searched in the
directories given in the :envvar:`PATH` environment variable.