Finally I solved the problem. It appears to be the parameter compat="html5"
. The default html spec is html4. And also I need the xpath
parameter to select the <header>
content as well as the <body>
content. Hope the following code could be of some help to others:
function requestCrossDomain(url, cb) {
yql = "http://query.yahooapis.com/v1/public/yql?" +
"q=" +
encodeURIComponent('select * from html where url="' + url + '" ') +
encodeURIComponent('and compat="html5" and xpath="//html/head|//html/body"') +
"&format=xml&callback=?";
$.getJSON(yql, function (data) {
if(data.results)
cb(data.results);
});
}