使用ajax加载IFRAME中的页面 [英] Load the page inside of IFRAME using ajax

查看:1031
本文介绍了使用ajax加载IFRAME中的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用IFRAME加载您的网页?我想这是可能的。



例如,我在下面的iframe。

 < iframe id =iframewidth =1024height =600src =http://www.sample.com>< / iframe> 

我希望 www.sample.com 页面在此iframe中加载通过不只是将URL添加到 src 属性中,而是使用ajax获取当前页面数据并使用IFRAME标记加载。我正在考虑这个问题,因为我大部分时间都对IFRAME缓存有很大的问题。



我也试过这个东西,但是在我的结尾它并不能完美地工作。

 < iframe id =iframewidth =1024height =600src =http:// www.sample.com?random=1422841682605\"\"></iframe> 



我想将它应用到我的响应式工具上,如下图所示:如果您需要实际视图 点击此处





感谢你们,如果有什么想法的话。

/ p>

  src ='data:text / html; charset = utf-8,'+ 
encodeURICompone nt(//逃避URL格式
'<!DOCTYPE html>'+
'< html lang =en>'+
'< body>< h1> ;另一个文件!< / h1>< / body>'+
'< / html>'
);


how about loading your page using IFRAME ? I was thinking if this is possible ..

Example, i have this iframe below.

<iframe id="iframe" width="1024" height="600" src="http://www.sample.com"></iframe>

I want the www.sample.com page to load inside this iframe by not simply add the URL into src attribute, instead I'll get the current page data using ajax and to load using IFRAME tag. I'm thinking about this because I have a big problem on IFRAME cache most of the time.

I also try this thing but, it does not work perfectly on my end.

<iframe id="iframe" width="1024" height="600" src="http://www.sample.com?random=1422841682605""></iframe>

random is change everytime i load this iframe.

I want to apply it on my responsive tool like on the image below. If you need an actual view click here.

Thanks guys if have some idea out there .

解决方案

You can still use src but supply data URL like this:

src = 'data:text/html;charset=utf-8,' + 
    encodeURIComponent( // Escape for URL formatting
        '<!DOCTYPE html>'+
        '<html lang="en">'+
        '<body><h1>Another document!</h1></body>'+
        '</html>'
    );

这篇关于使用ajax加载IFRAME中的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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