Difference between revisions of "OpenURL"

From Lazarus wiki
Jump to navigationJump to search
m (Alextpp moved page openurl to OpenURL: proper casing)
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
==Definition==
 
==Definition==
 +
 
Unit: Lazarus '''lclintf'''
 
Unit: Lazarus '''lclintf'''
  
<syntaxhighlight>
+
<syntaxhighlight lang="pascal">
 
function OpenURL(AURL: String): Boolean;
 
function OpenURL(AURL: String): Boolean;
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Official documentation: [http://lazarus-ccr.sourceforge.net/docs/lcl/lclintf/openurl.html]
+
Official documentation: [http://lazarus-ccr.sourceforge.net/docs/lcl/lclintf/openurl.html OpenUrl]
  
 
==Description==
 
==Description==
'''openurl''' opens an URL with the default/registered web browser as specified by the operating system.
 
  
Apparently spaces need to be encoded (as %20); see [http://www.ietf.org/rfc/rfc1738.txt]
+
<syntaxhighlight lang=pascal inline>OpenUrl</syntaxhighlight> opens a URL with the default/registered/preferred web browser as specified by the operating system.
 +
 
 +
Spaces in URLs need to be encoded as %20; see [http://www.ietf.org/rfc/rfc1738.txt RFC1738]. When using the file:// URI scheme, you should not encode spaces with %20.
 +
 
 +
== Warning ==
 +
 
 +
On Windows with Lazarus versions older than revision r40490 (2013-03-06), opening a URL using the file:// URI scheme (to open a local file) may fail if there are spaces in the filename.
 +
 
 +
With those older Lazarus versions, you should enclose the entire string in double quotation marks, if you are on an NT platform.
 +
 
 +
This is unfortunately system and browser dependant. Note: opening a file:// URL with spaces on Win9x will probably fail if you enclose the URL in quotation marks (See {{MantisLink|21659}}).
  
{{Warning|On Windows with Lazarus versions older than development version r40490 (2013-03-06), opening an URL using the file:// URI scheme (to open a local file) may fail if there are spaces in the filename.<br>
+
On Windows it is preferable to not use <syntaxhighlight lang=pascal inline>OpenUrl</syntaxhighlight> with the file:// URI scheme, but use [[opendocument|OpenDocument]] with the filename instead because of the above mentioned problems.
With those older Lazarus versions, you should enclose the entire string in double quotes, if you are on an NT platform.<br>
 
This is unfortunately system and browser dependant. Note: opening a file:// URL with spaces on Win9x will probably fail if you enclose the URL in quotes (See bug 21659 in the bugtracker).<br>
 
On Windows it is preferable to not use OpenUrl with file:// URI scheme, but use [[opendocument|OpenDocument]] with the filename instead because of the above mentioned problems.<br>
 
When using the file:// URI scheme, you should not escape spaces with %20.}}
 
  
==Example==
+
== Example ==
<syntaxhighlight>
+
 
 +
<syntaxhighlight lang="pascal">
 
uses  
 
uses  
 
...
 
...
 
lclintf
 
lclintf
 
...
 
...
OpenURL('http://wiki.lazarus.freepascal.org/');
+
OpenURL('https://wiki.lazarus.freepascal.org/');
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
== See also ==
 +
 +
* [[opendocument|OpenDocument]]
 +
* [[macOS Open Sesame|macOS open]]
 +
 
[[category:Lazarus]]
 
[[category:Lazarus]]
 
[[category:lclintf]]
 
[[category:lclintf]]
 
[[Category:Inter-process communication]]
 
[[Category:Inter-process communication]]

Latest revision as of 23:58, 31 March 2021

Definition

Unit: Lazarus lclintf

function OpenURL(AURL: String): Boolean;

Official documentation: OpenUrl

Description

OpenUrl opens a URL with the default/registered/preferred web browser as specified by the operating system.

Spaces in URLs need to be encoded as %20; see RFC1738. When using the file:// URI scheme, you should not encode spaces with %20.

Warning

On Windows with Lazarus versions older than revision r40490 (2013-03-06), opening a URL using the file:// URI scheme (to open a local file) may fail if there are spaces in the filename.

With those older Lazarus versions, you should enclose the entire string in double quotation marks, if you are on an NT platform.

This is unfortunately system and browser dependant. Note: opening a file:// URL with spaces on Win9x will probably fail if you enclose the URL in quotation marks (See Issue #21659).

On Windows it is preferable to not use OpenUrl with the file:// URI scheme, but use OpenDocument with the filename instead because of the above mentioned problems.

Example

uses 
...
lclintf
...
OpenURL('https://wiki.lazarus.freepascal.org/');

See also