Skip to content

Instantly share code, notes, and snippets.

@jbinto
Created January 13, 2016 07:32
Show Gist options
  • Star 32 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save jbinto/119c3f0e5735ab73faaa to your computer and use it in GitHub Desktop.
Save jbinto/119c3f0e5735ab73faaa to your computer and use it in GitHub Desktop.
Get title from remote HTML URL - without jQuery
// Only using native browser features (no jQuery).
// Uses `fetch`, `DOMParser` and `querySelectorAll`.
const getTitle = (url) => {
return fetch(`https://crossorigin.me/${url}`)
.then((response) => response.text())
.then((html) => {
const doc = new DOMParser().parseFromString(html, "text/html");
const title = doc.querySelectorAll('title')[0];
return title.innerText;
});
};
var urls = [
'https://medium.com/@unakravets/the-sad-state-of-entitled-web-developers-e4f314764dd',
'http://frontendnewsletter.com/issues/1#start',
'https://groups.google.com/forum/#!topic/v8-users/PInzACvS5I4',
'https://www.youtube.com/watch?v=9kJVYpOqcVU',
]
// This one keeps the order the same as the URL list.
Promise.all(
urls.map((url) => getTitle(url))
).then((titles) => {
console.log(titles);
});
@Aryan-Oswal-93
Copy link

πŸ‘πŸ»πŸš€πŸš€πŸš€πŸš€

@circles-00
Copy link

Proxy down, use: https://allorigins.win/

@odebroqueville
Copy link

Just can't get it to work because of CORS blocking!

@directionforward
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment