Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | File | Q1655 [ previous next ]

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

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?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.