Is there a standard way of getting the HTMLDocument object
representation of a remote page using Javascript? If I request an
HTML page, the xmlHttpRequest returns either text or an XMLDocument.
I can't figure out how to convert the former into an HTMLDocument
object and the latter doesn't seem to work if the page isn't valid
XHTML.
If that approach isn't going to work, I've envisioned hacks involving
loading a page in an invisible iframe instead of using xmlHttpRequest,
but didn't want to rehack the wheel.
Also, this is for a Firefox extension, so I really only need something
that will work with Firefox, although it would be cool to find out how
to do this generally.
Thanks!
Jeff 5 3179 http://www.quirksmode.org/dom/importxml.html to grab the XML nodes and their
content into the document markup by means of DOM by using the .responseXML, as
for inserting it from .responseText property, just use .innerHTML property, be
keen that .innerHTML can be have issues since it calls on the html parser to
parse the markup and sometimes when you try to access its childNodes in DOM,
they may go astray. If you do not need to crawl its childNodes,
then .innerHTML works fine.
Danny
On Mar 10, 7:03 pm, Danny <dann90...@bluebottle.comwrote:
http://www.quirksmode.org/dom/importxml.htmlto grab the XML nodes and their
content into the document markup by means of DOM by using the .responseXML, as
for inserting it from .responseText property, just use .innerHTML property, be
keen that .innerHTML can be have issues since it calls on the html parser to
parse the markup and sometimes when you try to access its childNodes in DOM,
they may go astray. If you do not need to crawl its childNodes,
then .innerHTML works fine.
Thanks for the suggestions.
I want to do the later, but it's not exactly straightforward from
there. First, I need to somehow create a HTMLDocument, then I'm
guessing insert an HTMLElement node, then remove the <htmland </
htmltags from the responseText, then set the innerHTML of the
HTMLElement to that text.
If I do that, will XPATH queries work on the resulting document? I'm
happy even if it only works on Firefox 2+.
Thanks,
Jeff
>
Danny
Jeff wrote:
On Mar 10, 7:03 pm, Danny <dann90...@bluebottle.comwrote:
>http://www.quirksmode.org/dom/importxml.htmlto grab the XML nodes and their content into the document markup by means of DOM by using the .responseXML, as for inserting it from .responseText property, just use .innerHTML property, be keen that .innerHTML can be have issues since it calls on the html parser to parse the markup and sometimes when you try to access its childNodes in DOM, they may go astray. If you do not need to crawl its childNodes, then .innerHTML works fine.
Thanks for the suggestions.
I want to do the later, but it's not exactly straightforward from
there. First, I need to somehow create a HTMLDocument, then I'm
guessing insert an HTMLElement node, then remove the <htmland </
htmltags from the responseText, then set the innerHTML of the
HTMLElement to that text.
If I do that, will XPATH queries work on the resulting document? I'm
happy even if it only works on Firefox 2+.
Thanks,
Jeff
>> Danny
mydiv=document.createElement('div');
mymarkup=OBJ.responseText.replace(/<\/*(html|head|body)>/i,''); // what would
there be an <htmlin the fragment markup, it should just be markup to be
inserted in a page's body
mydiv.innerHTML=mymarkup;
document.body.appendChild(mydiv);
if atop of the page
document.body.InsertBefore(mydiv, document.body.firstChild);
Danny
On Mar 10, 7:28 pm, Danny <dann90...@bluebottle.comwrote:
Jeff wrote:
On Mar 10, 7:03 pm, Danny <dann90...@bluebottle.comwrote:
>http://www.quirksmode.org/dom/importxml.htmltograb the XML nodes and their
content into the document markup by means of DOM by using the .responseXML,
as for inserting it from .responseText property, just use .innerHTML
property, be keen that .innerHTML can be have issues since it calls on the
html parser to parse the markup and sometimes when you try to access its
childNodes in DOM,
they may go astray. If you do not need to crawl its childNodes,
then .innerHTML works fine.
Thanks for the suggestions.
I want to do the later, but it's not exactly straightforward from
there. First, I need to somehow create a HTMLDocument, then I'm
guessing insert an HTMLElement node, then remove the <htmland </
htmltags from the responseText, then set the innerHTML of the
HTMLElement to that text.
If I do that, will XPATH queries work on the resulting document? I'm
happy even if it only works on Firefox 2+.
Thanks,
Jeff
Danny
mydiv=document.createElement('div');
mymarkup=OBJ.responseText.replace(/<\/*(html|head|body)>/i,''); // what would
there be an <htmlin the fragment markup, it should just be markup to be
inserted in a page's body
mydiv.innerHTML=mymarkup;
document.body.appendChild(mydiv);
if atop of the page
document.body.InsertBefore(mydiv, document.body.firstChild);
Well, for instance if I request a URL, say http://www.yahoo.com/ and
to easily select elements of its DOM (It's a Greasemonkey script, so
the cross-site restrictions don't apply). So, I need a way of
creating a HTMLDocument and then initializing it. I assume I can do
something similar to the code you've provided, but it won't be exactly
like that.
-Jeff
Jeff wrote:
If that approach isn't going to work, I've envisioned hacks involving
loading a page in an invisible iframe instead of using xmlHttpRequest,
but didn't want to rehack the wheel.
Also, this is for a Firefox extension, so I really only need something
that will work with Firefox, although it would be cool to find out how
to do this generally.
With Mozilla, you need an invisible frame to parse a text/html document
into a DOM HTMLDocument. There is so far no API to parse a complete
text/html document into a DOM tree.
--
Martin Honnen http://JavaScript.FAQTs.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: James Marshall |
last post by:
I'm writing a library where I want to override document.write(), but for
all document objects; thus, I want to put it in the prototype. I tried
Document.prototype.write= my_doc_write ;
but it...
|
by: kavitha |
last post by:
Can we construct a HTMLDocument? I mean something like
this
string outerHTML = "<HTML><BODY>Some sample
text...</BODY></HTML>";
HTMLDocument doc = new HTMLDocument();
doc.addElement("HTML");...
|
by: pierre |
last post by:
Hi, I got a problem which may easy to resolve, but I can't
find any issue:
I want to parse html files, so, I want first get it from an
url, and I do like that:
Dim objMSHTML As New...
|
by: Filippo Bettinaglio |
last post by:
VS2005, C#
I have developed a UserControl embedded in a HTML web page. And I can
access to the DOM with the following code:
HTML page:
……..
<BODY onload=loadDoc()>
…….
|
by: Irfan |
last post by:
Hello,
I want to load HTML file into HTMLDocument object. I don't want to use
webbrowser object or any asyncrohonous call to load HTML into this file.
Like if I call HTTPWebRequest to download...
| |
by: forcedfx |
last post by:
I'm faced with a bit of a conundrum. I'm trying to post a form using the HTMLDocument object. I've got the form posting working prefectly, however, in order to retrieve the HTML page that contains...
|
by: Jeff |
last post by:
Hello,
I assigned a new object to a local variable ("req") in a function (see
below). The local variable "req" is obviously destroyed when the
function exits, but should the object referenced by...
|
by: nmm32 |
last post by:
I am trying to use Ajax with JSP to populate a 2nd drop down list based on the chosen option of the first one. I am getting the error "Object Expected" on the line 13-14 of the HTML:
<script...
|
by: nickin4u |
last post by:
I have a application that is used to automate certain task,
I have been using mshtml.HTMLDocument class but certain events like click a button do not fire. I have tried a number of combinations but...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |