简体   繁体   English

通过从另一个HTML页面调用在另一个HTML页面的div中加载HTML页面

[英]Loading a Html page in a div of an another html page by calling from a different html page

Suppose I have three html pages those are index.html , page1.html and page2.html . 假设我有三个html页面,分别是index.htmlpage1.htmlpage2.html

Currently I am on page2.html and have a list of items with each hyperlinking to some pages. 目前,我在page2.html并有一个项目列表,每个项目都超链接到某些页面。 Say one links to page1.html . 说一个链接到page1.html

Is it possible to load page1.html in a div which is in index.html from page2.html ? 是否可以在page1.html中的index.html中的div加载page2.html

Any help will be appreciated. 任何帮助将不胜感激。

You can use jQuery .load() for this 您可以为此使用jQuery .load()

$('#div').load('pageUrl');

Or if you need any callback then you can use 或者,如果您需要任何callback则可以使用

$('#div').load('pageUrl', function(){
    // your code here
});

For detail reference you can click here 有关详细信息,请单击此处

Yes it is possible, 对的,这是可能的,

You can request index.html using jQuery ajax as follows: 您可以使用jQuery ajax请求index.html,如下所示:

$.ajax({
    url: "/index.html"
}).done(function(htmlData) {
    var htmlContent = $.parseHTML(htmlData).find("div"); // Here you pass the div reference of content you want to load
    $("div.targetDiv").html(htmlContent);
});

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

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