I want to know what could be the best way to get the title, keywords and content visible to the user from responseText using fetch api (Is there a way to not send cookies when making an XMLHttpRequest on the same origin?)
At the moment, I use regular expressions to get the title from the response text, for example:
var re_title = new RegExp("<title>[\n\r\s]*(.*)[\n\r\s]*</title>", "gmi");
var title = re_title.exec(responseText);
if (title)
title = title[1]
And to get the content in the keyword meta tag, i need to employ several regular expressions.
To get the content visible to the user, we don't need tags like script, div etc. also, we don't need the text between script tags. This is to get only the words which are meaningful in the body of the response.
I think (also as per various stackoverflow post) using regular expressions for this is just not the right approach. What could be the alternative?