如何将文档内容动态加载到iframe中? [英] How to dynamic load the document content into an iframe?

查看:290
本文介绍了如何将文档内容动态加载到iframe中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这样做

|--------------------------|
|                A         |
|        ____________      |
|       |            |     |
|       |            |     |
|       |      B     |     |
|       |            |     |
|       |____________|     |
|                          |
|__________________________|

B页面在A页面内,我要将所有js,css插入A页面,我想分离B页面,我设计它使用iFrame,并动态获取b页面。但是如果我使用src在B页面iframe,A页面js,css无法控制它...我如何完全插入所有的B页面代码在A页面,但不需要复制&粘贴所有从B页到A页的代码?谢谢。

The B page is inside the A page, and I want to insert all the js, css, into the A page, and I want to separate the B page, and I design it to use a iFrame, and get the b page dynamically. But if I use the src in the B page iframe, the A page js, css can't control it... How can I exactly insert all the B page code inside the A page, but don't need copy&paste all the code from B page to A page? Thank you.

推荐答案

您可能需要查看一个AJAX解决方案。这样就避免了iframe和相关的复杂性。在A页面上,您可以创建具有特定ID的div标签。然后使用AJAX可以将B页面的内容加载到div标签中。

You may want to look at an AJAX solution. This way you avoid the iframe and associated complexity. On the A page you can create a div tag with a specific id. Then using AJAX you can load the content of the B page into the div tag.

然后,可以直接通过A页面上的代码来操作加载的HTML,因为它本质上是一页。

The HTML that is loaded can then directly be manipulated by the code on your A page since it is essentially one page.

如果你使用纯javascript,那么你会发现你需要的所有信息在本教程

If you are using plain javascript then you will find all the info you need in this tutorial.

如果在另一方面,你希望使用jQuery,简单为:

If on the other hand you wish to use jQuery then it is as simple as:

  $('#myDiv').load('B.html');

其中myDiv是您的div的ID。

where myDiv is the ID of your div.

这篇关于如何将文档内容动态加载到iframe中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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