Main Content

web

Open web page or file in browser

Description

example

web(url) opens the page specified by url in a web browser. If url is an external site, web(url) opens the page in your system browser. Otherwise, the page opens in the MATLAB® web browser. If multiple browsers are open, the page displays in the one that was most recently used.

example

web(url,opt) opens the page using the specified browser option, such as '-new' to create a new browser instance or '-browser' to use the system 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 preferences.

example

web(url,opt1,...,optN) opens the page using one or more browser options.

web opens an empty MATLAB web browser.

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,h] = web(___) returns a handle to the MATLAB web browser that allows you to close it using the command close(h). If the page opens in a system 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 MATLAB web browser.

[stat,h,url] = web(___) returns the URL of the current page in the MATLAB web browser. If the page opens in a system browser, web returns an empty URL.

Examples

collapse all

Open the MathWorks® Web site home page in the system browser.

url = 'https://www.mathworks.com';
web(url)

Create a local HTML file by publishing an example program file.

htmlFile = publish("fourier_demo2.m");

View the file by specifying the file name.

web(htmlFile)

View the file in a new instance of the browser 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 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://<html><h1>Hello World</h1></html>')

Input Arguments

collapse all

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, then the page opens in your system browser. If url corresponds to a file in the installed product documentation, then the page displays in the MATLAB Help browser instead of the web browser.

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 browser instead of the MATLAB web browser. If url is an external site, web always opens the page in your system 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 preferences.

'-new'

Opens the page in a new instance of the MATLAB web browser. Does not apply when the page opens in your system browser.

'-noaddressbox'

Opens the page in a browser that does not display the address box. Only applies to new instances of the MATLAB web browser.

'-notoolbar'

Opens the page in a browser that does not display a toolbar or address box. Only applies to new instances of the MATLAB web browser.

Example: '-new','-noaddressbox'

Output Arguments

collapse all

Browser status, returned as an integer with one of these values:

0

Found and started system browser.

1

Could not find system browser.

2

Found, but could not start system browser.

Handle to the most recent MATLAB web browser, returned as a scalar instance of the associated Java® class. If the page opens in a system 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. Other MATLAB functionality also uses the web function, such as links to external sites from the Help browser.

Current page address in the most recent MATLAB web browser, returned as a character vector or string. url has the same data type as the input argument url. If the page opens in a system browser, url is empty, ''.

Limitations

  • MATLAB Online™ only supports the web(url) syntax. Calling web(url) in MATLAB Online opens the page specified by url in your web browser.

  • The web function does not support the text:// URL scheme when opening pages in the system 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 browser.

  • If you are displaying Japanese streaming text in the MATLAB web browser, specify a header that includes the charset attribute. For example:

    web(['text://<html><head><meta http-equiv="content-type" ' ...
         'content="text/html;charset=utf-8"></head><body>TEXT</body></html>']) 

Version History

Introduced before R2006a

expand all