更新3
user52875也有一个很好的答案,Can WT present web pages as part of the host page?它使用 HTML,实际上比使用 JS 容易得多。为您+1,好先生。
更新2
弄清楚了,工作代码如下。您需要在 javascript 中使用 iframe 将另一个页面嵌入到您自己的页面中。 IP地址是本地网络上的另一台PC,运行带有一些内容的WT服务器,我能够连接并查看WT服务器的内容。此外,由于某种原因,iframe 无法连接到谷歌或雅虎等浏览网站。尽管我确信某处有一个单独的问题。
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
这似乎需要将 JS iframe 与 WT 对象一起使用。 Javascript 不是我的强项,但我已经使用 WT doJavaScript() 命令( Embedding Ventus in WT 和 Using ACE with WT )完成了一些应用程序嵌入。如果我找到在 WT 中嵌入页面的正确方法,我将进一步更新这篇文章。预先感谢您的帮助。
WText* text = new WText(root);
string command = ""; //TODO: Proper creation and use of JS iframe.
text->doJavaScript(command);
原帖
因此,我正在尝试创建一个小型 WT 应用程序,其中有一组 anchor 或一个文本框和一个用于输入和切换页面的按钮。基本设置如下:
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
所以,我想做的是在不离开主页的情况下呈现不同页面的内容。这可能吗?我一直在阅读文档并浏览小部件库,但到目前为止还没有找到任何与将远程内容嵌入到您自己的页面中相关的内容。我的长期目标是让 anchor 连接到同一网络上另一台 PC 的 IP 地址,并在我自己的主机页面中呈现在该 PC 上运行的 WT 服务器的内容,而无需离开它。预先感谢您的帮助!
最佳答案
这里有一个类似的问题及其答案。希望对您有所帮助。
关于javascript - WT 能否将网页呈现为主页的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17933867/