Project

General

Profile

How to add a static HTML file into project?

Added by Richard Li almost 12 years ago

There is a static index.html file in my project.

Is there any method loading this file into my wt programme immediately?

I try to use the class WText just like:

root()->addWidget(new WText("contents in html file"));

but it only works when the content which inside the

Additional, could I processing a dom or find a dom in a existed html file using wt which like

...?

Thanks for helping~!


Replies (3)

RE: How to add a static HTML file into project? - Added by Wim Dumon almost 12 years ago

You can't just stuff a HTML file with body, html, header, ... tags in another page. If your index.html only contains markup tags (h1, h2, 3h, b, im, ...), the method you use with WText is correct. WText will filter all javascript and active tags from the text you pass on in order to protect against XSS attacks.

If you want to display an existing page as is, I think your best option is to use an iframe. You can do this as such:

root()->addWidget("<iframe src='http://myserver.com/mypage.html'></iframe>", XHTMLUnsafeText);

XHTMLUnsafeText turns of the XSS filter (iframes are iirc considered unsafe), so never put anything that can be influenced by a user in such a WText widget unless you know what you're doing!

BR,

Wim.

RE: How to add a static HTML file into project? - Added by Richard Li almost 12 years ago

Oh, I found I am a little familer with Wt, thanks for your explain and I solved the problem.

But, er.....another problem comes out... T_T

I want to change the background color, don't use the picture.

Generally, I add an attribute into body's tag: bgcolor="#FF00FF";

In wt, I only find the function setBodyClass(), so I use it to load a css file, but no-effect.

Should I add an metalink before?

In addition, is there any function to clear the wt's default style and css......?

_

RE: How to add a static HTML file into project? - Added by Wim Dumon almost 12 years ago

I would do something along these lines:

In C:

// call WApplication::useStyleSheet to load a CSS file
useStyleSheet("/css/mystylesheet.css");

mystylesheet.css:

body {
    background:#f0f
}

So depending on how you structure your CSS selector, you don't need a style class on your body element.

Wim.

    (1-3/3)