Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1655 How can I read the contents of another HTML page?

You are here: irt.org | FAQ | JavaScript | File | Q1655 [ previous next ]

With Internet Explorer 4+ you can use the innerHTML property to read the contents of another frame (including an inline frame (note that this will only work for a page on the same server as the JavaScript code - otherwise you'll get a "denied" message):

<iframe src="testpage.htm" name="myIframe"></iframe>

<form>
<input type="button" value="Read HTML" onClick="alert(document.myIframe.document.innerHTML)">
</form>

With Netscape Navigator you can use a signed script and LiveConnect:

<script language="JavaSCript"><!--
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;
}

alert (fetchURL (location.href))
//--></script>

But it needs to be signed or otherwise trusted for locations other than the one the script is loaded from.

Feedback on 'Q1655 How can I read the contents of another HTML page?'

©2018 Martin Webb