If I understand you correctly, grab the content between the body tags with a regex.
$.get($(this).attr("href"), function(data) {
var body=data.replace(/^.*?<body>(.*?)</body>.*?$/s,"$1");
$("body").html(body);
});
EDIT
Based on your comments below, here's an update to match any body tag, irrespective of its attributes:
$.get($(this).attr("href"), function(data) {
var body=data.replace(/^.*?<body[^>]*>(.*?)</body>.*?$/i,"$1");
$("body").html(body);
});
The regex is:
^ match starting at beginning of string
.*? ignore zero or more characters (non-greedy)
<body[^>]*> match literal '<body'
followed by zero or more chars other than '>'
followed by literal '>'
( start capture
.*? zero or more characters (non-greedy)
) end capture
</body> match literal '</body>'
.*? ignore zero or more characters (non-greedy)
$ to end of string
Add the 'i' switch to match upper and lowercase.
And please ignore my comment regarding the 's' switch, in JavaScript all RegExp are already single-line by default, to match a multiline pattern, you add 'm'. (Damn you Perl, interfering with me when I'm writing about JavaScript! :-)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…