Is there any method that will return the title of the web page given its URL?
I don't mean the title of the current page which can be gotten from doing document.title
, I mean getting the title of another web page.
Is there any method that will return the title of the web page given its URL?
I don't mean the title of the current page which can be gotten from doing document.title
, I mean getting the title of another web page.
You can't access this is the site is on a different domain. That would be a security violation of the same origin policy.
Otherwise, you could load the other web page into a hidden iframe
and use this:
document.getElementById('myIframe').contentWindow.document.title;
Actually I semi-lied. It is a security violation to do this, but IE has a bug whereby you can access the content via VBScript. Not sure if this has been patched yet.
maybe ajax can do this, but by primitive tools, you cant! (js is client side!)
Yes you can and its very simple.
chrome.topSites.get(function(info){ //fetching the top sites visited in chrome
var xyz=document.getElementsByClassName('urclassname');
for(var i=0;i<info.length;i++) {
console.log(info[i]); //check the data fetched by info
xyz[i].setAttribute("urclassattribute",info[i].title); //set the title of the fetched url
}
});
Suppose my top visited site is Facebook, so the console.log(info[i]) will give the value in the browser console as:
Object
title : "(3) Facebook" url : "https://www.facebook.com/" proto : constructor : ƒ Object() hasOwnProperty : ƒ hasOwnProperty() isPrototypeOf : ƒ isPrototypeOf() propertyIsEnumerable : ƒ propertyIsEnumerable() toLocaleString : ƒ toLocaleString() toString : ƒ toString() valueOf : ƒ valueOf() defineGetter : ƒ defineGetter() defineSetter : ƒ defineSetter() lookupGetter : ƒ lookupGetter() lookupSetter : ƒ lookupSetter() get proto : ƒ proto() set proto : ƒ proto()
So basically you get the title of the website.