On a SharePoint online modern site, I need a JS variable to search for a specific string of text in the code of the page (this variable is for Google Tag Manager). I have tried:
function() {
var pageContent = document.documentElement.innerHTML;
if (pageContent.indexOf("TEXTTOSEARCHFOR") > -1) {
return true;
} else {
return false;
}
}
It does not work, I get no result even when I can see the specific word in the code. I have tried outerHTML instead of innerHTML too.
Maybe this is because the HTML of a SPO page is handled in a different way than a more traditional web page?
This function was given to me by online friends, I know almost nothing in programming (but I know how Tag Manager quite well).