Guest Will Posted November 12, 2007 Share Posted November 12, 2007 From within Javascript I want to do:if string is in current page {}how do I do this? Link to comment Share on other sites More sharing options...
Ingolme Posted November 12, 2007 Share Posted November 12, 2007 I made up this little script. It needs the innerText property in order to be cross-browser. Unfortunately, that makes it non-W3C-compliant. But until some browsers improve their compliance to web standards it will always be hard to make standard W3C compliant scripts. function searchPage(obj) { if(document.documentElement.textContent) { allText = document.body.textContent; } else { allText = document.body.innerText; } if(allText.indexOf(obj) != -1) { //Execute some code }} Search: <input type="text" id="something" /><input type="button" value="Search" onclick="searchPage(document.getElementById('something').value)" /> Link to comment Share on other sites More sharing options...
Synook Posted November 13, 2007 Share Posted November 13, 2007 Why not use document.getElementsByTagName('body')[0].innerHTML ? Link to comment Share on other sites More sharing options...
Ingolme Posted November 13, 2007 Share Posted November 13, 2007 Because innerHTML will also return HTML tags. And imagine you search for "table", and it says it found it but you can't see the word "table" anywhere at all (supposing you're a visitor that doesn't know anything about HTML). Link to comment Share on other sites More sharing options...
Synook Posted November 14, 2007 Share Posted November 14, 2007 Oh yeah - true Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.