#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    How can I load an external static html file to a JavaScript var?


    I am new to JavaScript. I would like to use a small routine within my iOS project to search html file using javaScript.

    Let's say I have "test.html" that I would like to search for a "phrase".

    Is there a way to load the file into a var?
    I know I can use getelementbyID(..) for some controls. But, how to do it for a static file?
    The goal for me is to highlight certain words/text within the html document - I figured HTML can't do it, but javaScript would allow me.

    Thanks
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    If the HTML file is on the same domain as the page hosting the JavaScript then you can use an XHR to retrieve the HTML contents of the file. I'm not sure how this works within the context of an iOS app.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    165
    Rep Power
    18
    Personally when i want to include another HTML page to play with through javascript i will use a hidden iframe. Im sure there are better ways to do this but it is how are company does it.
    Code:
    <iframe id="SomeHtml" src="somehtml.html" style="display:none">
    This will allow the contents of somehtml.html to be accessible by javascript through

    Code:
    document.getElementById('SomeHtml').ContentWindow.document.body.innerHtml
    It will also be completely invisible on the html page

    Originally Posted by software2007
    I am new to JavaScript. I would like to use a small routine within my iOS project to search html file using javaScript.

    Let's say I have "test.html" that I would like to search for a "phrase".

    Is there a way to load the file into a var?
    I know I can use getelementbyID(..) for some controls. But, how to do it for a static file?
    The goal for me is to highlight certain words/text within the html document - I figured HTML can't do it, but javaScript would allow me.

    Thanks

IMN logo majestic logo threadwatch logo seochat tools logo