【问题标题】:Can WT present web pages as part of the host page?WT 可以将网页呈现为主机页面的一部分吗?
【发布时间】:2013-07-29 20:46:28
【问题描述】:

更新 3

user52875 也有一个很好的答案,Can WT present web pages as part of the host page?,它使用 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() 命令(Embedding Ventus in WTUsing ACE with WT)做了一些应用程序的嵌入。如果我找到将页面嵌入 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 服务器的内容而不离开它。提前感谢您的帮助!

【问题讨论】:

    标签: javascript c++ web embedding wt


    【解决方案1】:

    这里有一个类似的问题及其答案。希望对您有所帮助。

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

    【讨论】:

    • 说明不是很清楚,认为他们确实确认可以在 WT 容器中加载网页并将其显示在页面上。如何使用这个
    • 想通了,查看帖子顶部的更新 2 以获取答案。
    【解决方案2】:

    这样做:

    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 的解决方案是不可能的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-19
      • 2012-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多