Highlight search text in iframe in asp.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sangam56
    New Member
    • Nov 2007
    • 68

    Highlight search text in iframe in asp.net

    Hi all.
    I have an iframe in an asp.net web page (Display.aspx).

    Code:
    <iframe id="iframe1" runat="server" src="temp/test.html"></iframe>
    Now I need to highlight a search text, say 'test' in the Display.aspx page. The source of iframe is dynamically assigned and search text is also changeable. This means I am dealing with dynamic search text and html page. Please suggest me how could I highlight the search texts in the iframe placed in the asp.net web page.

    Thanks in advance. Happy Programming!
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Have you considered using JavaScript to solve this problem?


    -Frinny

    Comment

    • sangam56
      New Member
      • Nov 2007
      • 68

      #3
      Hi,
      I have used jquery highlighter. It is highlighting the words in the aspx page. But I am unable to highlight the search words within the html files embedded in the aspx page.

      We can embed an html file into an aspx page in various ways, using Response.WriteF ile or Server.Transfer or using iframe also. In all these methods, I have been unable to highlight the words in the html file. Any idea please? Thank you.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        if the text to be highlighted is in the iframe, it could be that the Javascript is not loaded or the text not accessed. Frames (resp. their content) in any way are separate HTML pages! (though there are ways for Javascript to interact between pages)

        since asp is executed on the server (right?) this reduces to a frame-javascript problem.

        PS: I gave up on frames long ago, so you might have to ask in the Javascript forum for the appropriate solution

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          To get access to the iframe document, there are one or two differences: contentDocument says W3C and the standards-compliant browsers, and contentWindow.d ocument according to IE. So, try something like this:
          Code:
          if (iframeObj.contentDocument) doc = iframeObj.contentDocument;
          else if (iframeObj.contentWindow) doc = iframeObj.contentWindow.document;

          Comment

          Working...