Sign in Join
Wiki copytemporary

Webbrowser: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11This page summarizes various ways to display HTML pages from a Pascal program, ranging from calling an external browser to adding a component capable of rendering the html page into a form.
22
33## Starting a web browser to show a page/URL
44
55### OpenURL
66
77OpenURL is simplest way of opening URLs in general. This procedure will detect the default web browser and open URL from parameter in it. It can be used for mail addresses of the form 'mailto:aname@AnAddress?subject=:::A subject line', web addresses 'http://' and files 'file:///'.
88
99``` pascal
1010uses LCLIntf;
1111...
1212OpenURL('http://www.lazarus.freepascal.org');
1313```
1414
1515### Finding the default web browser
1616
1717Every platform has a mechanism for its default web browser. The LCL unit **lazhelphtml** contains a class [[THTMLBrowserHelpViewer]] to start a web browser for the LCL help system.
1818
1919You can use its method FindDefaultBrowser to find the default browser and the parameter to start. For example:
2020
2121``` pascal
2222uses
2323 Classes, ..., LCLProc, LazHelpHTML;
2424
2525...
2626
2727implementation
2828
2929procedure TMainForm.Button1Click(Sender: TObject);
3030var
3131 v: THTMLBrowserHelpViewer;
3232 BrowserPath, BrowserParams: string;
3333begin
3434 v:=THTMLBrowserHelpViewer.Create(nil);
3535 v.FindDefaultBrowser(BrowserPath,BrowserParams);
3636 debugln('Browser=',BrowserPath,' Params=',BrowserParams);
3737 v.Free;
3838end;
3939```
4040
4141This gives for example under Ubuntu (Linux):
4242
43-`Browser=/usr/bin/xdg-open Params=%s`
43+```text
44+Browser=/usr/bin/xdg-open Params=%s
45+```
4446
4547Under Windows:
4648
47-`Browser=C:\windows\system32\rundll32.exe Params=url.dll,FileProtocolHandler %s`
49+```text
50+Browser=C:\windows\system32\rundll32.exe Params=url.dll,FileProtocolHandler %s
51+```
4852
4953Under macOS:
5054
51-`Browser=/usr/bin/open Params="%s"`
55+```text
56+Browser=/usr/bin/open Params="%s"
57+```
5258
5359### Starting the browser
5460
5561Once you know the command line and parameters you can use [[TProcessUTF8]] to start the browser:
5662
5763``` pascal
5864uses
5965 Classes, ..., LCLProc, LazHelpHTML, UTF8Process;
6066
6167...
6268
6369implementation
6470
6571procedure TMainForm.Button1Click(Sender: TObject);
6672var
6773 v: THTMLBrowserHelpViewer;
6874 BrowserPath, BrowserParams: string;
6975 p: LongInt;
7076 URL: String;
7177 BrowserProcess: TProcessUTF8;
7278begin
7379 v:=THTMLBrowserHelpViewer.Create(nil);
7480 try
7581 v.FindDefaultBrowser(BrowserPath,BrowserParams);
7682 debugln(['Path=',BrowserPath,' Params=',BrowserParams]);
7783
7884 URL:='http://www.lazarus.freepascal.org';
7985 p:=System.Pos('%s', BrowserParams);
8086 System.Delete(BrowserParams,p,2);
8187 System.Insert(URL,BrowserParams,p);
8288
8389 // start browser
8490 BrowserProcess:=TProcessUTF8.Create(nil);
8591 try
8692 BrowserProcess.CommandLine:=BrowserPath+' '+BrowserParams;
8793 BrowserProcess.Execute;
8894 finally
8995 BrowserProcess.Free;
9096 end;
9197 finally
9298 v.Free;
9399 end;
94100end;
95101```
96102
97103## Integrate web browser component in application
98104
99105### TurboPower Internet Pro
100106
101107Lazarus provides the package TurboPowerIPro (lazarus/components/turbopower_ipro/turbopoweripro.lpk) with the following features:
102108
103109- It contains a control to put onto a form. When you install the package in the IDE, you get some new components in the palette, so you can drop them onto a form just like any LCL control.
104110- It is written completely in Pascal and therefore works on all platforms out of the box without any extra installation.
105111- You have the full control, what files/urls are opened.
106112- It does not have all the features of a full webbrowser. No multimedia stuff, javascript or flash. This must be implemented by you.
107113
108114There are some examples in lazarus/components/turbopower_ipro/examples demonstrating how to open a local html file with some images, hyperlinks and history buttons. See the [[IPro tab]] on the [[Component Palette]].
109115
110116### WebView4Delphi
111117
112118[[WebView4Delphi]] allows to embed Chromium-based web browsers in your Delphi or Lazarus applications using the WebView2 runtime. It uses many of the tricks from CEF4Delphi and you will notice many similarities if you used it.
113119
114120There are a few things pending like the "windowless mode".
115121
116122### TWebBrowser WebKit (macOS Cocoa)
117123
118124TWebBrowser control is implemented only for the LCL Cocoa widgetset for macOS by wrapping the WebView class that's part of every Mac's WebKit framework. Note that by default macOS blocks calls to insecure HTTP sites. You can relax this restriction by setting the *NSAllowsArbitraryLoads* key in your application's [[macOS property list files|Info.plist]] file, but for testing you might stick with HTTPS sites. This control does not add any bulk to your app and does not require installation of any additional libraries. Everything it needs is already on your Mac and is accessible via the FPC CocoaAll unit. [Source](https://macpgmr.github.io/MacXPlatform/lclwebbrowser-src.zip).
119125
120126### QT Webkit
121127
122128When using the Qt widgetset, you can use the Qt Webkit to embed a browser into a LCL form. Lazarus demo is available on [FPC Qt4 Binding Web Page](http://users.telenet.be/Jan.Van.hijfte/qtforfpc/fpcqt4.html).
123129
124130### THtmlPort
125131
126132[[THtmlPort]] is a Lazarus/Free Pascal version of Dave Baldwin's HTML Components, including THtmlViewer, TFrameViewer and TFrameBrowser.
127133
128134### HtmlViewer
129135
130136The [HtmlViewer](https://github.com/BerndGabriel/HtmlViewer) component for Delphi and Lazarus, set consists of:
131137
132138- THtmlViewer
133139- TFrameViewer
134140- TFrameBrowser
135141
136142### fpCEF3
137143
138144[[fpCEF3]] is a Chromium Embedded Framework for Free Pascal.
139145
140146### CEF4Delphi
141147
142148[[CEF4Delphi]] is updated Chromium Embedded Framework, which supports Lazarus.
143149
144150### GeckoPort
145151
146152[[GeckoPort]] is a Lazarus/Free Pascal version of Takanori Ito's Gecko SDK for Delphi, including the TGeckoBrowser component.
147153
148154### LazActiveX
149155
150156[[LazActiveX]] allows to import MS Internet Explorer type library.
151157
152158### LazWebkit
153159
154160[LazWebkit](http://sourceforge.net/p/lazwebkit/wiki/Home/) is a project focused to provide browser and composer web content features for Lazarus IDE based projects. Currently it's implemented only for GTK2 widgetset.
155161
156162## See also
157163
158164- [[Executing External Programs]]
159165- [[fphttpclient]] Part of fcl-web that can be used stand-alone to retrieve HTTP-Content
160166- [[fpbrowser]] web browser written in Lazarus
161167- [[fpwebview]] cross-platform library for Linux, macOS and Windows for building desktop applications using Pascal and web technology
162168- [[Windows Programming Tips|Using Windows native WinInet for web retrieval]]
163169- [[macOS NSURLSession]] - the replacement for [[macOS NSURLConnection|NSURLConnection]] for web retrieval.
164170
165171---
166172*From the Free Pascal wiki, page "Webbrowser", as it stood on 2022-02-18 after a change by PierceNg, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history