Internet Explorer: how to search in TextRange with findText method when search string contains line breaks?

Answered Internet Explorer: how to search in TextRange with findText method when search string contains line breaks?

  • 19 aprilie 2012 12:46
     
      Are cod

    Here I created an example demonstrating the problem:

    <HTML>
    <BODY>
    Leonardo da Vinci was one of the great masters of the High 
    Renaissance, especially <br><br>in painting, sculpture, architecture, 
    engineering, and science.
    </BODY>
    </HTML>
    <SCRIPT>
       var oRange = document.body.createTextRange();
          // record the current position in a bookmark
       var sBookMark = oRange.getBookmark();  
    
       var searchString = 'especially \r\n\r\nin painting'
       alert(oRange.findText(searchString, 0, 6)) //returns false
       alert(oRange.text.indexOf(searchString)) //returns '72', which means that string that I'm looking for is correct
    
    </SCRIPT>
    How should I modify search string and/or change function parameters for it to find what I want?

    For you convenience, here is the link to function documentation: 

    http://msdn.microsoft.com/en-us/library/ms536422(v=vs.85).aspx

    Thanks.

Toate mesajele

  • 3 mai 2012 01:30
    Moderator
     
     Răspuns Are cod

    Hi, please try the following codes:

    var searchString = 'especially in painting'
    alert(oRange.findText(searchString));