Documentation Center

  • Trial Software
  • Product Updates

web

Open Web page or file in browser

Syntax

  • stat = web(___)
  • [stat,h] = web(___) example
  • [stat,h,url] = web(___)

Description

web opens an empty MATLAB® Web browser.

example

web(url) opens the page specified by url 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.

example

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

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.

example

[stat,h] = web(___) returns a handle to a MATLAB Web browser that allows you to close it using the command close(h). 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.

Examples

expand all

Web Page in MATLAB Web Browser

Open the MathWorks Web site home page.

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

Open the page in a new instance of the browser that does not include a toolbar.

web(url,'-new','-notoolbar')

File in MATLAB Web Browser

View an HTML file that resides on your system.

Create an HTML file by publishing an example program file. Copy the program file to the current folder so that the code can run during the publishing process.

program = fullfile(matlabroot,'help','techdoc',...
          'matlab_env','examples','fourier_demo2.m');
copyfile(program);
htmlFile = publish('fourier_demo2.m');

View a file by specifying the file name.

web(htmlFile)

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)

Web Page in System Browser

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

url = 'http://www.mathworks.com';
web(url,'-browser')

Email from System Browser

Send 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)

Handle to MATLAB Web Browser

Open the MathWorks Web site home page, and then close the browser using its handle.

url = 'http://www.mathworks.com';
[stat,h] = web(url);

Close the browser window.

close(h)

Text Displayed in MATLAB Web Browser

View formatted text using the text:// URL scheme.

web('text://<html><h1>Hello World</h1></html>')

Input Arguments

expand all

url — Web page address or file locationstring

Web page address or file location, specified as a string. File locations can include an absolute or relative path.

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: 'http:\\www.mathworks.com'

Example: 'myfolder/myfile.html'

opt — Browser option'-browser' | '-new' | '-noaddressbox' | '-notoolbar'

Browser option, specified as one of the following strings. Options can appear in any order.

'-browser'

Opens the page in a system browser window instead of the MATLAB 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 MATLAB Web browser window. Does not apply to the 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

expand all

stat — Browser status0 | 1 | 2

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

0

Found and launched system browser.

1

Could not find system browser.

2

Found, but could not launch system browser.

h — Handle to most recent MATLAB Web browserscalar

Handle to the most recent MATLAB Web browser, returned as a scalar instance of the associated Java® class.

If you do not request the handle when you open the page, be aware that this 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.

url — Current page addressstring

Current page address in the most recent MATLAB Web browser, returned as a string.

More About

expand all

Tips

  • If you plan to deploy an application that calls the web function using the MATLAB Compiler™ product, then use the '-browser' option.

  • 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>']) 

See Also

|

Was this topic helpful?