我使用href
在点击的链接.load()
上加载页面内容,如下所示:
$("html").on('click', 'a', function(event) {
event.preventDefault(); // obviously
var url = this.href + " #main"; // holds the content of #main at a given url
$('#ajax-container').load(url); // loads that content into #ajax-container
document.title = "?";
});
如何获取已加载页面的标题并显示它?
答案 0 :(得分:3)
尝试这个:
var url = this.href; //following techfoobar's comment
$('#ajax-container').load(url,function(data){
document.title = $($.trim(data)).find('title').text();//$.trim() used for old IE to move unexpected characters
});
但是,在$('#ajax-container')
所以请改用$ .get():
var url = this.href; //following techfoobar's comment
$.get(url,function(data){
document.title = $('<div/>').html($.trim(data)).find('title').text();
$('#ajax-container').html($('<div/>').html($.trim(data)).find('body').html());
});