0

As JScript is the 'out of browser', Microsoft ES3 variant of Javascript, it's hard to do something simple as parsing a HTML string into an object.

As mentioned, JScript does reside not in a browser, so it does not have the standard document type, nor does it have the domparser.

I can make a document object as so:

 var document = new ActiveXObject('htmlfile')
 document.innerHTML = http.responseText

and while this will render the html response into a document, I cannot use getElementsByClassName, TagName or even ID - which is exactly what I need to do with the html responses I'm looking at (a mix of those mentioned).

I've tried using John Resig's "pure javascript HTML parser", but that won't run in ES3 and I am not versed enough in JScript/ES3 to understand why not.

https://johnresig.com/blog/pure-javascript-html-parser/

Ultimately, I want to parse the HTML file in a document object, and be able to pull elements by their class, id, tagname etc. For me it sounds like this should be easy, but it isn't.

Any help would be appreciated.

1 Answer 1

1

getElementById and getElementsByTagName seem to work:

var document = new ActiveXObject('htmlfile');
document.open();
document.write('<html><div id="div1" class="class1">test</div></html>');
document.close();

WScript.Echo(document.getElementById("div1").id);

WScript.Echo(document.getElementsByTagName("div")[0].id);

WScript.Echo(document.getElementsByTagName("div")[0].className);

test output

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you - you are right, I put the html string in as "=innerHTML", but didn't open/write/close; however, it seems like getElementsByClassName still doesn't work. Any magic to get that to work?
No, getElementsByClassName really doesn't seem to be supported, but you can use the className property to do your own filtering

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.