Entry
JavaScript: How can client-side JavaScript retrieve the HTML of the file that it's in?
May 2nd, 2003 11:36
Mark Szlazak, Knud van Eeden, Martin Honnen, Nathan Wallace, Martin Honnen
IE5:
var html = document.documentElement.outerHTML;
IE4 only allows the body to be read:
var bodyHTML = document.body.innerHTML;
NN4 calling into java:
function fetchURL(url) {
if ((location.host == '' && url.indexOf(location.protocol) == -1)
||
url.indexOf(location.host) == -1)
{
netscape.security.PrivilegeManager.enablePrivilege
("UniversalConnect");
}
var dest = new java.net.URL(url);
var dis = new java.io.DataInputStream(dest.openStream());
var res = "";
while ((line = dis.readLine()) != null) {
res += line;
res += java.lang.System.getProperty("line.separator");
}
dis.close();
return res;
}
//example call
var html = fetchURL(location.href)
NN6: you can try to generate the HTML source from the document tree, see
http://www.faqts.com/knowledge-base/view.phtml/aid/970/fid/126/lang/en
which emulates innerHTML/outerHTML of IE for NN6
------------------------------------------------------------------------
--- Knud van Eeden - 27 September 2020 - 02:13 -------------------------
For example:
<HTML>
<HEAD>
<TITLE>
</TITLE>
</HEAD>
<BODY
onLoad='
var htmlS = document.documentElement.outerHTML;
alert( htmlS );
'
>
</BODY>
</HTML>
---
[Internet: see also:
http://www.faqts.com/knowledge_base/view.phtml/aid/5785]
---
[Internet: see also:
http://www.faqts.com/knowledge_base/view.phtml/aid/11672/fid/613
]
---
[Internet: see also a similar question at:
http://www.faqts.com/knowledge_base/view.phtml/aid/9072/fid/53]
------------------------------------------------------------------------