如何才能用div和Javascript替换iframe? [英] How exactly can I replace an iframe with a div and Javascript?

查看:376
本文介绍了如何才能用div和Javascript替换iframe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面可以将外部HTML页面加载到iFrame中.我面临着两个问题:

I have a page that loads an external HTML page into an iFrame. There are two problems I am facing with this:

  1. iFrame始终是固定高度,但我希望它扩展 垂直取决于内容的高度.
  2. iFrame中的内容不能继承CSS样式 附加到包含它的HTML页面上.里面的HTML iFrame必须具有自己的链接或单独的样式表.
  1. The iFrame is always a fixed height, but I want it to expand vertically depending on the height of the content.
  2. The content inside the iFrame can not inherit the CSS styles attached to the HTML page that contains it. The HTML inside the iFrame has to have it's own link or separate style sheet.

我可能在这两个方面都错了,因此,如果是我,请告诉我,然后我将继续使用iFrame.

I could be wrong about either of those points, so if I am, please let me know and then I will continue to use the iFrame.

否则,是否有一个简单的 Javascript 调用可以将外部HTML文件加载到 DIV 中?

Otherwise, is there a simple Javascript call that can load an external HTML file into a DIV?

请明确一点,因为似乎有些人误解了我:

Just to be clear, since it seems some people have misunderstood me:

我正在问如何用DIV和Javascript替换iframe ,以便获得我上面提到的功能.我不是正在寻找使iFrame行为不同的方法.

I am asking how to replace an iframe with a DIV and Javascript in order to get the functionality I mention above. I am not looking for ways to make iFrames behave differently.

(我以为这很普遍,但是我在本网站和网络上发现的大多数问题和信息似乎都是针对特定情况的,并要求我不需要其他功能,但是,如果我错过了一些东西,而且这是重复的,一旦关闭,我也不会感到生气.)

推荐答案

您可以进行ajax调用来获取您的html页面并将其添加到div中.例如,使用JQuery:

You can make an ajax call to fetch your html page and add it to the div. For example using JQuery:

$.get('yourPage.html', function(data) { $('#yourDiv').html(data); });

$.get('yourPage.html', function(data) { $('#yourDiv').html(data); });

更多信息,请访问: http://api.jquery.com/jQuery.get/

这篇关于如何才能用div和Javascript替换iframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆