Question

Update 3

user52875 also has a very good answer, Can WT present web pages as part of the host page? which uses HTML, and is actually a lot easier than messing with JS. +1 to you good sir.

Update 2

Figured it out, working code bellow. You need to use an iframe in javascript to embed another page in your own. The IP address is another PC on a local network that runs a WT server with some content, I was able to connect and view the contents of the WT server. Also, for some reason the iframe is unable to connect to browsing sites such as google or yahoo. Though I am sure there is a separate question on that that somewhere.

WText* text = new WText(root);
string command = string("var ifr") + " = document.createElement('iframe');" + 
                 //"ifr.src = 'http://javascript.info';" +         //Works
                 //"ifr.src = 'http://www.escapistmagazine.com';" +//Works
                 //"ifr.src = 'http://escapistmagazine.com';" +    //Works
                 //"ifr.src = 'http://google.com';" +              //Doesn't work
                 //"ifr.src = 'http://www.google.com';" +          //Doesn't work
                 "ifr.src = 'http://12.3.45.678:8080/';" +         //Works
                 "ifr.width = 1500;" +
                 "ifr.height = 700;" +
                 "document.body.appendChild(ifr);";
text->doJavaScript(command);

Update 1

It would seem that this requires the use of JS iframes with WT objects. Javascript is not my strong point, but I have done some embedding of applications using WT doJavaScript() command(Embedding Ventus in WT and Using ACE with WT). I will update the post further if I find the proper way to embed the page in WT. Thanks in advance for any help.

WText* text = new WText(root);
string command = ""; //TODO: Proper creation and use of JS iframe.
text->doJavaScript(command);

Original Post

So, I am trying to create a small WT app in which I have a collection of anchors, or a text box and a button to type in and switch pages. The basic setup is like this:

WContainerWidget* root = wApp->root();

WAnchor* Google = new WAnchor("http://www.google.com/", "Google", root);
root->addWidget(new Wt::WBreak());

WAnchor* Yahoo = new WAnchor("http://www.yahoo.com/", "Yahoo", root);
root->addWidget(new Wt::WBreak());

Wt::WLineEdit* GotoBar = new Wt::WLineEdit(root);
Wt::WPushButton* GotoButton = new Wt::WPushButton("Goto address", root);

//TODO: Some kind of widget that will present the content of the anchors
//      or the GotoBar

So, what I am trying to do is present the content of a different page without leaving the host page. Is this possible? I've been reading documentation and browsing the widget gallery, but so far have not found anything that relates to embedding remote content into your own page. My long term goal is to have an anchor connect to an IP address of another PC, on the same network, and present the content of a WT server running on that PC in my own host page without leaving it. Thanks in advance for any help!

Was it helpful?

Solution

There is a similar question and its answer here. Hope it helps.

http://www.mail-archive.com/witty-interest@lists.sourceforge.net/msg01578.html

OTHER TIPS

Do this:

WText *myIframe = new WText(this);
// Very important: if your url comes from a user, sanitize it or you create a
// very nice XSS attack vector. AFAIK not all functions required are publicly
// available in Wt. XHTMLUnsafeText switches of Wt's built-in XSS filer, which
// filters out iframes.
myIframe->setText("<iframe src='http://12.34.56.78:8080/' width=100 height=100></iframe>", XHTMLUnsafeText);

Using this method, you can also remove the iframe, that is not possible with your JS-based solution you mention in your update.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top