Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8407383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:20:57+00:00 2026-06-09T23:20:57+00:00

Some background: I’m developing a web based mobile application using JavaScript. HTML rendering is

  • 0

Some background:
I’m developing a web based mobile application using JavaScript. HTML rendering is Safari based. Cross domain policy is disabled, so I can make calls to other domains using XmlHttpRequests. The idea is to parse external HTML and get text content of specific element.
In the past I was parsing the text line by line, finding the line I need. Then get the content of the tag which is a substring of that line. This is very troublesome and requires a lot of maintenance each time the target html changes.
So now I want to parse the html text into DOM and run css or xpath queries on it.
It works well:

$('<div></div>').append(htmlBody).find('#theElementToFind').text()

The only problem is that when I use the browser to load html text into DOM element, it will try to load all external resources (images, js files, etc.). Although it isn’t causing any serious problem, I would like to avoid that.

Now the question:
How can I parse html text to DOM without the browser loading external resources, or run js scripts ?
Some ideas I’ve been thinking about:

  • creating new document object using createDocument call (document.implementation.createDocument()), but I’m not sure it will skip the loading of external resources.
  • use third party DOM parser in JS – the only one I’ve tried was very bad with handling errors
  • use iframe to create new document, so that external resources with relative path will not throw an error in console
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:20:59+00:00Added an answer on June 9, 2026 at 11:20 pm

    It seems that the following piece of code works great:

    var doc = document.implementation.createHTMLDocument("");
    doc.documentElement.innerHTML = htmlBody;
    var text = $(doc).find('#theElementToFind').text();
    

    external resources aren’t loaded, scripts aren’t being evaluated.

    Found it here:
    https://stackoverflow.com/a/9251106/95624

    Origin:
    https://developer.mozilla.org/en/DOMParser#DOMParser_HTML_extension_for_other_browsers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First some background: VB.NET 2005 Application that accesses a MS-SQL back-end, using multiple Web
Some Background info: My web application stores some XML in a Text column of
First Some Background I'm planning out the architecture for a new PHP web application
My application has some background music playing on a loop, using a MediaPlayer .
Some background information: We have an ancient web-based document database system where I work,
Some background. I'm using Rails 3 for a carpooling application. I'm using fullcalendar as
Some background I'm currently building a predominantly classic web app (rather than a single
Some background I've created a GUI using a combination of a GUIDE built Figure
Some background: I've created a Swing application which uses the Substance LaF (Thanks again,
Some background I'm currently working on a mobile site so I keep switching user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.