Reputation: 37
How to fetch any page title using URL in javascript front end. But I don not want to load the full page in response this method takes a lot of time to find result. Is there any quick way to achieve this goal?
const proxyUrl = 'https://api.allorigins.win/get?url='+encodeURIComponent(url);
const response = await fetch(proxyUrl);
const data = await response.json();
const html = data.contents;
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const pageTitle = doc.querySelector('title').textContent;
Upvotes: 0
Views: 134