简体   繁体   English

如何在没有 iframe 的页面中加载页面

[英]How to load a page within a page without an iframe

I want to load a page of my website within another page, but there are some problems.我想在另一个页面中加载我网站的一个页面,但是有一些问题。 First of all I can't use iframe, because I need to change some styles and scripts in the loaded content.首先我不能使用iframe,因为我需要在加载的内容中更改一些styles和脚本。 Second, I don't want the styles and scripts of the loaded content to be loaded for the parent page, just like an iframe that it's styles and scripts, don't affect the parent page.其次,我不希望为父页面加载 styles 和加载内容的脚本,就像 iframe 是 styles 和脚本一样,不要影响父页面。

I get the page content with XMLHttpRequest and load it to a DOM with jQuery, but I want the loaded styles and scripts only for this DOM.我使用 XMLHttpRequest 获取页面内容并使用XMLHttpRequest将其加载到 DOM,但我想要加载的 styles 和仅用于此 DOM 的脚本。 Is there anyway to do this?有没有办法做到这一点?

Best way to do that is to use css for the included content that is restricted to that namespace.最好的方法是将 css 用于仅限于该命名空间的包含内容。

 #sub-page h1 { font-size: 16px; }
 <div id="main-page"> <h1>big text</h1> The text below would be loaded by ajax. <div id="sub-page"> <h1>not big text</h1> <h2 style="font-size: 16px">Also not-big text</h2> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM