Main Content

web

Open web page or file in browser

Description

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 web 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 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 preferences.

example

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

example

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 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 MATLAB web browser.

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

Examples

collapse all

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("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 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://<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 web browser. Otherwise, the page opens in the MATLAB 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 web browser instead of the MATLAB web browser. 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 preferences.

'-new'

Opens the page in a new instance of the MATLAB web browser. 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 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 web browser.

1

Could not find system web browser.

2

Found, but could not start system web browser.

Handle to the most recent MATLAB web browser, returned as a scalar instance of the associated Java® 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 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 the system web 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 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 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