Difference between revisions of "Development/Architecture/KDE3/KHTML"

Jump to: navigation, search
m (technology hyperlinks)
m (Text replace - "<code cppqt>" to "<syntaxhighlight lang="cpp-qt">")
Line 11: Line 11:
you a complete application with which you can already browse the web:
you a complete application with which you can already browse the web:
<code cppqt>
<syntaxhighlight lang="cpp-qt">
#include <khtml.h>
#include <khtml.h>
#include <kapp.h>
#include <kapp.h>

Revision as of 18:29, 29 June 2011

KHTML - KDE's HTML library

KHTML is an XML/HTML4 compliant HTML library, with support for DOM, Java, JavaScript and Cascading Style Sheets (CSS).

You can get an overview of KHTML's current capabilities here.

Small example

Using KHTML in your program is quite easy. The following example shows you a complete application with which you can already browse the web:

#include <khtml.h>
#include <kapp.h>

int main(int argc, char *argv[])
    KApplication a(argc, argv, "testkhtml");

    KHTMLWidget *html = new KHTMLWidget;


    QWidget::connect(html, SIGNAL(setTitle(const QString &)),
                     html, SLOT(setCaption(const QString &)));

This small example already gives you a functional browser, that lets you browse
the web (you'll need the <tt>kio_http</tt> executable from KDE though to access
non local files). Just try <tt>testkhtml http://www.kde.org</tt> and you will
get a widget showing KDE's home page.

<tt>KHTML</tt> has a lot of functionality. Almost everything you'll ever need
can be accessed through the member functions of the class KHTMLWidget.

== Document Object Model (DOM) ==

<tt>KHTML</tt> provides a mostly complete implementation of
[http://www.w3.org/DOM/ Dom Level 1 and 2].

The DOM is an implementation using internal classes to hold the document's data.
The classes accessing the DOM are using a refcounting scheme to hold the data.
Thus the DOM does the memory management for you. You can just use the classes
defined in the DOM header files to access parts of the document. As long as you
don't use pointers, you will not get memory leaks.

You can easily access the document being shown by the
<tt>KHTMLWidget::document()</tt> method, from where you can
get access to every part of the document.

== Java ==

Thanks to the work of Richard Moore, <tt>KHTML</tt> can display Java applets.
Java is not enabled by default, but you can do so by using
<tt>KHTMLWidget::setEnableJava(true);</tt>, and setting the environment variable
<tt>CLASSPATH</tt> to:


You will need to have the java developers kit installed though. I tested it
with JDK-1.1.7, and don't know if it'll run with other versions of JDK or with

== JavaScript (ECMA-Script) ==

The JavaScript support aims at compliance with the ECMAScript Language
specification [http://www.ecma.ch/ecma1/STAND/ECMA-262.HTM ECMA-262] 3rd edition.
This roughly equals JavaScript 1.5.

== Cascading Style Sheets (CSS) ==

Cascading style sheets 2.1 are mostly supported now.

''Initial Author:'' [mailto:knoll@kde.org Lars Knoll]


Content is available under Creative Commons License SA 4.0 unless otherwise noted.
*/ ?>