我的目标是在我的页面上打印外部页面的标题,而不需要在服务器端加载前者。
目前,我正在使用 jQuery 和 Google 的搜索 API。看看以下解决方案的hackyness:
//Use google search api to get page title for link
var url = "http://ajax.googleapis.com/ajax/services/search/web?q=" + **URL** + "&v=1.0&callback=?"
//Set URL for link
$("#link").attr("href", content);
//Execute google api JSON query
$.getJSON(url, function (data) {
//Insert the unformatted title of the first result into the page
$("#title").append(data.responseData.results[0].titleNoFormatting);
});
^ 效果很好,但仅适用于在 Google 上编入索引的网页,这些网页是提交 URL 时的第一个结果。
谁能做得更好?