web - Open web page or file in browser - MATLAB (original) (raw)
Open web page or file in browser
Syntax
Description
web([url](#btigyx%5F-url))
opens the page specified byurl
in a web browser. If url
is an external site or a documentation page (including custom documentation pages),web(url)
opens the page in your system web browser. Otherwise, the page opens in the HTML Viewer. If multiple browsers are open, the page displays in the one that was most recently used.
web([url](#btigyx%5F-url),[opt](#btigyx%5F-opt))
opens the page using the specified browser option, such as'-new'
to create a new web browser instance or'-browser'
to use the system web browser.
On Microsoft® Windows® and Apple Macintosh platforms, the operating system determines the system web browser. On other systems, the default is the Mozilla® Firefox® browser, but you can change the default using MATLAB® Web settings.
web([url](#btigyx%5F-url),opt1,...,optN)
opens the page using one or more browser options.
web
opens an empty HTML Viewer tab. If a HTML Viewer tab is already open, web
does nothing.
[stat](#btigyx%5F-stat) = web(___)
returns the status of the operation: 0
if successful,1
or 2
if unsuccessful. You can include any of the input arguments in previous syntaxes.
[[stat](#btigyx%5F-stat),[h](#btigyx%5F-h)] = web(___)
returns a handle to a HTML Viewer tab that allows you to close it using the command close(h)
. If the page opens in the system web browser, web
returns an empty handle.
If you do not specify any inputs to the web
function, such as [stat,h] = web
, then the handle corresponds to the most recently used HTML Viewer.
[[stat](#btigyx%5F-stat),[h](#btigyx%5F-h),[url](#btigyx%5F-url)] = web(___)
returns the URL of the current page in the HTML Viewer. If the page opens in the system web browser, web
returns an empty URL.
Examples
Open the MathWorks® Web site home page in the system web browser.
url = 'https://www.mathworks.com'; web(url)
Create a local HTML file by publishing an example program file.
htmlFile = publish("penny.m",outputDir=pwd);
View the file by specifying the filename.
View the file in a new tab in the HTML Viewer that does not include a toolbar.
web(htmlFile,"-new","-notoolbar")
Alternatively, you can use the file:///
URL scheme, as long as you include the full path. The publish
function returns the path in the htmlFile
output.
url = "file:///" + htmlFile; web(url)
Send an email from your system web browser's default mail application using the mailto:
URL scheme.
To run this example, replace the value for email
with a valid email address.
email = 'myaddress@provider.ext'; url = ['mailto:',email]; web(url)
View formatted text using the text://
URL scheme.
web('text://
Hello World
')Input Arguments
Web page address or file location, specified as a character vector or a string. File locations can include an absolute or relative path.
If url
is an external site or a documentation page (including custom documentation pages), then the page opens in your system web browser. Otherwise, the page opens in the HTML Viewer.
Example: 'https://www.mathworks.com'
Example: "myfolder/myfile.html"
Browser option, specified as one of the following. Options can appear in any order.
'-browser' | Opens the page in your system web browser instead of the HTML Viewer. If url is an external site, web always opens the page in your system web browser.On Microsoft Windows and Apple Macintosh platforms, the operating system determines the system web browser. On other systems, the default is the Mozilla Firefox browser, but you can change the default using MATLAB Web settings. |
---|---|
'-new' | Opens the page in a new HTML Viewer tab. Does not apply when the page opens in your system web browser. |
'-noaddressbox' | Opens the page in a browser that does not display the address box. Only applies to new HTML Viewer tabs. |
'-notoolbar' | Opens the page in a browser that does not display a toolbar or address box. Only applies to new HTML Viewer tabs. |
Example: '-new','-noaddressbox'
Output Arguments
Browser status, returned as an integer with one of these values:
0 | Found and started system web browser. |
---|---|
1 | Could not find system web browser. |
2 | Found, but could not start system web browser. |
Handle to the most recent HTML Viewer tab, returned as a scalar instance of a matlab.htmlviewer.HTMLViewer class. If the page opens in the system web browser, h
is empty,[]
.
If you do not request the handle when you open the page, the handle might not correspond to your most recent use of the web
function as MATLAB uses the web
function for other functionality.
Current page address in the most recent HTML Viewer tab, returned as a character vector or string. url
has the same data type as the input argument url
. If the page opens in the system web browser, url
is empty,''
.
Limitations
- MATLAB Online™ only supports the
web(url)
syntax. Callingweb(url)
in MATLAB Online opens the page specified byurl
in your web browser. - The
web
function does not support thetext://
URL scheme when opening pages in the system web browser or from a deployed application.
Tips
- If you plan to deploy an application that calls the
web
function using the MATLAB Compiler™ product, use the'-browser'
option to open all pages in the system web browser. - If you are displaying Japanese streaming text in the HTML Viewer, specify a header that includes the
charset
attribute. For example:
web(['text://<meta http-equiv="content-type" ' ...
'content="text/html;charset=utf-8">TEXT'])
Version History
Introduced before R2006a
When you use the web
function to open a local URL or file, the page now opens in the HTML Viewer. Previously, the page opened in the MATLAB web browser. As part of this change, the MATLAB web browser has been removed.
The web
function now returns a handle to the most recent MATLAB web browser as a matlab.htmlviewer.HTMLViewer
object. In previous releases, the web
function returns the handle as an instance of a Java® class. With this change, some methods that were previously supported in the returned handle are no longer supported.
In most cases, you do not need to make any changes to your code. However, if your code uses methods that are not supported in the returnedmatlab.htmlviewer.HTMLViewer
object, you must update your code.
When you use the web
function to open a file in the installed documentation, the file now opens in your system web browser. Previously, the file opened in the Help browser.
In a future release, the web function will return a handle to the most recent MATLAB web browser as a MATLAB class. Currently, the web
function returns the handle as a Java class. With this change, some methods that were previously supported in the returned handle will no longer be supported.
In most cases, you will not need to make any changes to your code. However, if you are using methods that are not supported in the returned MATLAB class, you will need to update your code.
The web
function now opens external sites using your system web browser. Previously, you could open external sites using the MATLAB web browser by clearing the Use system web browser when opening links to external sites (recommended) setting. This setting has been removed.
The web
function does not return a handle or URL for pages that open in the system web browser. This includes all external pages, which by default open in your system web browser, unless configured otherwise in the MATLAB Web settings.
To update your code, remove the handle and URL output arguments from instances of the web
function. This table shows examples of how you can update your code.
Before | After |
---|---|
[stat,h] = web('https://www.mathworks.com','-browser') | stat = web('https://www.mathworks.com','-browser') |
[stat,h,url] = web('https://www.mathworks.com','-browser') | stat = web('https://www.mathworks.com','-browser') |
The web
function now opens external sites using your system web browser by default. Previously, the web
function opened external sites using the MATLAB browser. Using the system web browser is recommended when opening external sites.
To use the MATLAB browser as the default browser for external sites, go to theHome tab, and in the Environment section, click Settings. Select > and in the System Web browser section, clear theUse system web browser when opening links to external sites (recommended) option.