2

I'm trying to find some text on the page, like:

function crossBrowserFind() {
    var str = "Hell";
    if (window.find) {        // Firefox, Google Chrome, Safari
        found = window.find(str);
    }else {
        if (document.body.createTextRange) { // Internet Explorer, Opera before version 10.5
            var textRange = document.body.createTextRange();
            if (textRange.findText) {   // Internet Explorer     
                found = textRange.findText(str);
                if (found) {
                    textRange.select();
                }
            }
        }
    }      
}

But the function named "createTextRange" is not supported when run in Microsoft Edge (win10 build 10162).

Does someone know how can I find the text in Microsoft Edge?

TylerH
  • 20,799
  • 66
  • 75
  • 101
apc2002
  • 21
  • 3
  • 1
    It still doesn't work in win10 release version – apc2002 Aug 05 '15 at 05:26
  • We are evaluating support for window.find in a future release, but it is [somewhat controversial](https://bugzilla.mozilla.org/show_bug.cgi?id=672395) even in browsers that support it. We removed IE specific calls like createTextRange as part of our [interoperability efforts](http://blogs.windows.com/msedgedev/2015/06/17/building-a-more-interoperable-web-with-microsoft-edge/). In the meantime, using a method like suggested in http://stackoverflow.com/questions/6240139/highlight-text-range-using-javascript may work. That code requires offsets but could be modified to search for substrings. – Charles Morris - MSFT Oct 02 '15 at 18:05
  • 2
    @CharlesMorris-MSFT - The MSDN docs about createTextRange() don't indicate any browser versions that this is or isn't included in.. I'd suggest adding that as you remove proprietary methods that are sure to still be in use around the web. – Rob Maurizi Feb 11 '16 at 15:30
  • @RobMaurizi Thanks for the suggestion! We are in the midst of a large documentation clean up and look forward to it launching. :) – Charles Morris - MSFT Feb 12 '16 at 18:09

0 Answers0