1

更新 3

user52875 也有很好的回答,WT 可以将网页呈现为主机页面的一部分吗?它使用 HTML,实际上比弄乱 JS 容易得多。+1 对你好先生。

更新 2

想通了,工作代码如下。您需要在 javascript 中使用 iframe 在您自己的页面中嵌入另一个页面。IP 地址是本地网络上的另一台 PC,它运行具有某些内容的 WT 服务器,我能够连接并查看 WT 服务器的内容。此外,由于某种原因,iframe 无法连接到浏览网站,例如 google 或 yahoo。虽然我确信在某个地方有一个单独的问题。

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);

更新 1

这似乎需要使用带有 WT 对象的 JS iframe。Javascript 不是我的强项,但我已经使用 WT doJavaScript() 命令(在 WT 中嵌入 Ventus 和在 WT 中使用ACE )完成了一些应用程序的嵌入。如果我找到将页面嵌入 WT 的正确方法,我将进一步更新帖子。提前感谢您的帮助。

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

原帖

因此,我正在尝试创建一个小型 WT 应用程序,其中有一组锚点,或者一个文本框和一个用于输入和切换页面的按钮。基本设置是这样的:

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

所以,我想做的是在不离开主机页面的情况下呈现不同页面的内容。这可能吗?我一直在阅读文档并浏览小部件库,但到目前为止还没有找到与将远程内容嵌入到您自己的页面相关的任何内容。我的长期目标是让锚点连接到同一网络上另一台 PC 的 IP 地址,并在我自己的主机页面中呈现在该 PC 上运行的 WT 服务器的内容,而无需离开它。提前感谢您的帮助!

4

2 回答 2

1

这里有一个类似的问题及其答案。希望能帮助到你。

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

于 2013-07-30T11:45:26.200 回答
1

做这个:

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);

使用此方法,您还可以删除 iframe,这对于您在更新中提到的基于 JS 的解决方案是不可能的。

于 2013-08-05T14:58:23.300 回答