【问题标题】:how to embed external html file into current html file but without iframe tag [closed]如何在没有 iFrame 的情况下在另一个页面内显示外部网站? [关闭]
【发布时间】:2016-12-30 08:15:04
【问题描述】:

我需要在没有 iFrame 的情况下在我的应用程序中打开外部网站 我还需要将一些标头值传递给该外部网站。

帮帮我..

【问题讨论】:

  • 请向我们展示您到目前为止所做的尝试

标签: jquery html web dojo


【解决方案1】:

iframe 的一些替代解决方案是:

AJAX - 您可以使用 XMLHttpRequest 对象检索数据并将其注入您的页面,例如在 div 中。使用 jQuery 的示例:

 $( "#result" ).load( "ajax/test.html" );

HTML5 Web Components - HTML Imports,Web Components 的一部分,允许将 HTML 文档捆绑到其他 HTML 文档中。这包括 HTML、CSS、JavaScript 或 .html 文件可以包含的任何其他内容。示例:

   <link rel="import" href="http://stackoverflow.com">

其他一些想法是:

&lt;object&gt; 标签 - 它定义了 HTML 文档中的嵌入对象。可用于 HTML 文件和多媒体内容,如音频、视频、小程序、ActiveX、PDF 和 Flash 或其他插件。

   <object data="http://stackoverflow.com" width="400" height="300" type="text/html">
        Alternative Content
    </object>

&lt;embed&gt; 标记 - 它为外部应用程序(例如插件)定义了一个容器,也可以被“破解”并用于显示 HTML 页面。

<embed src="http://stackoverflow.com" width=200 height=200 />

关于传递 HEADER 最好的解决方案是使用 AJAX 方法,这里是一个示例:

$.ajax({
    url: "http://stackoverflow.com",
    data: { uname: "test" },
    type: "GET",
    beforeSend: function(xhr){xhr.setRequestHeader('X-TOKEN', 'xxxxx');},
    success: function() { alert('Success!' + authHeader); }
});

or in this way,

$.ajax({
    url: "http://stackoverflow.com",
    data: { uname: "test" },
    type: "GET",
    headers:{ "X-TOKEN": 'xxxxx'},
    success: function() { alert('Success!' + authHeader); }
});

【讨论】:

  • 感谢您的回复。我已经尝试过上述方法。我无法将标头值传递给该站点。我怎样才能做到这一点
  • @PrabhuArumugam 欢迎您!考虑使用 jQuery 和 $.ajax 你可以使用 beforeSend 设置一个标题你可以在这里找到详细的文档api.jquery.com/jquery.ajax如果你需要更多信息请告诉我:)
  • 如果加载 url http:// 域 https:// 这个 .load 函数不起作用?
  • 关于默认标头 X-Frame-Options: "DENY" 的 Apache 配置:&lt;frame&gt;&lt;iframe&gt;&lt;embed&gt;&lt;object&gt; 不会呈现。见X-Frame-Options Header
【解决方案2】:

你可以试试这样的对象标签:

<object type="text/html" data="http://validator.w3.org/" width="800px" height="600px" />

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-20
  • 1970-01-01
  • 2011-02-08
  • 1970-01-01
  • 1970-01-01
  • 2017-08-14
  • 1970-01-01
相关资源
最近更新 更多