IFrame can't access / get IFRAME contents

Hi, I've been checking other solutions to this, and still can't get the IFRAME contents.


Please advise, this solution is not working for me: (browser id IE 6)

Here's what I use: <IFRAME>

<body>
<form id="form1">
<IFRAME src="http://www.google.com" name="myIframeId"></IFRAME>
</form>
<body>

<Javascript>
  Var vTheIFrameContents=top.frames['myIframeId'].document.documentElement.innerHTML;
#1) error returns: access denied

  Var vTheIFrameContents=top.frames['myIframeId'].Document.documentElement.innerHTML;
#2) object does not exist or is null

</Javascript>


...Thanks
paygoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

devicCommented:
you can not acces document object on diefferent domain
0
devicCommented:
try this:
===========================
<html>
<body onload=init()>
<hr>
<script>
function LoadPage(theURL,theID)
{


   var objSrvHTTP;
       objSrvHTTP = new ActiveXObject("Msxml2.XMLHTTP.4.0");
       objSrvHTTP.open ("GET",theURL,false);
       objSrvHTTP.send ("");

        document.getElementById(theID).innerHTML=objSrvHTTP.responseText;

}

function init()
{
      LoadPage("http://www.yahoo.com","yahoo")
      LoadPage("http://www.ebay.com","ebay")
}
</script>
<table width=555 cellspacing=0 cellpadding=0 border=3>
      <td valign=top id=yahoo></td>
      <td valign=top id=ebay></td>
</table>

</body>
</html>
0
archrajanCommented:
You can't access documents on another server than the frame that the
script is in. So while a frame on
  host1.domain.tld
can call a function in another frame on
  host1.domain.tld
you can't call functions in another frame on
  host2.domain.tld
or even a frame in another domain e.g.
  host.domain2.tld

~ ~ ~

Actually, for version 4 and higher of IE and Netscape it *is* possible
for host1.domain.tld to access script elements from host2.domain.tld,
as long as pages on both host1 and host2 include the statement

document.domain = 'domain.tld';

A caveat, however, this is broken for Netscape 4.03 and 4.04.

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

archrajanCommented:
SEE THIS FOR MORE INFO
With full DOM access we have two separate ways for two different
purposes to script an IFRAME.
Every IFRAME is contained as a window object in the
  window.frames
array (in both IE4+ and NN6 it seems), thus if you want to set the
location of an IFRAME or access its document and its content you
reference
  window.frames.iframeName
and then
  window.frames.iframeName.location.href
  window.frames.iframeName.document.links
etc.
If you want to access the HTMLIFrameElement the IFRAME tag creates you
access it with standard DOM methods:
  var iframeElement = document.getElementById('iframeId');
respectively
  var iframeElement = document.all['iframeId']
for IE4 and then you can set the html attributes e.g.
  iframeElement.width = 300;

The following contains examples of both uses: an empty IFRAME is
included in the page whose content is then change by getting the
iframe's window object and document.writing its document object. A
javascript link to access the iframe's content and another js link to
change the width of the iframe are provided.

<HTML>
<HEAD>
<SCRIPT>
var frameSrc = '';
frameSrc += '<HTML><BODY>';
frameSrc += '<BUTTON ONCLICK="alert(\'Kibology\');">';
frameSrc += 'button<\/BUTTON>';
frameSrc += '<\/BODY><\/HTML>';
var iframeWin, iframeElement;
function init () {
  iframeWin = window.frames.anIframe;
  iframeWin.document.open();
  iframeWin.document.write(frameSrc);
  iframeWin.document.close();
  iframeElement =
    document.getElementById ?
      document.getElementById('anIframe') :
      document.all['anIframe'];
}
</SCRIPT>


</HEAD>
<BODY ONLOAD="init();">
<A HREF="javascript: alert
(iframeWin.document.body.firstChild.nodeName); void 0">
show iframe first child
</A>
|
<A HREF="javascript: iframeElement.width = 300; void 0">
set width to 300
</A>
<BR>
<IFRAME ID="anIframe" NAME="anIframe" SRC="about:blank" WIDTH="100">
</IFRAME>
</BODY>
</HTML>
0
paygoAuthor Commented:
Basic question on domains,

Once this frame loads (using google as the source page):

<IFRAME src="http://www.google.com" name="myIframeId"></IFRAME>

and the content is captured in the IFrame (i.e the received html page), isn't that not
part of my local browers AND my local domain ?  

It would seem an easy step just to read the captured HTML contents from my local browser,
just like accessing the value of a text field?

...thanks  
0
paygoAuthor Commented:
RESTATE
Basic question on domains,

Once this frame loads (using google as the source page):

<IFRAME src="http://www.google.com" name="myIframeId"></IFRAME>

Once the content is captured in the IFrame (i.e the received html page), isn't that not
part of my local browers (client)  AND my local domain ?  

It would seem an easy step just to read the captured HTML contents from my local browser (client),
just like accessing the value of a text field?

...thanks  
0
devicCommented:
>>>Once the content is captured in the IFrame (i.e the received html page), isn't that not
part of my local browers (client)  AND my local domain ?

no.

if you need this only for you and only for local computer, then rename your *.html file to *.hta and it will work.
because HTA application can acces a different domain.
0
paygoAuthor Commented:
Thanks for the help.

Using the 'new ActiveXObject("Msxml2.XMLHTTP.4.0")' instead of the frames method returns
2 messages - that I would need to avoid.

IS there any way to avoid / bypass these two messages?

1) "The page is accessing Information that is not under it's control. This poses asecurity risk"

2) MSXML4.ACCESS is denied - (can't get to the page after this one)

Thanks
0
devicCommented:
unfortunately no, only on server side
0
paygoAuthor Commented:
Devisc thanks for the help - Are there any solutions to this?
Here's what I've found out so far.

1) I can't get to the HTML contents of an IFRAME that is pointing to a URL such as src=http://www.yahoo.com.

2) I can't use the ActiveXObject("Msxml2.XMLHTTP.4.0")
since A) Access is denied and b) this poses a security risk.

so.

Since I can see the source HTML loaded correctly in the IFRAME, is there a way to screen scrape the

contents using asp.net?

Thanks



 

0
devicCommented:
Paygo, as I said before on server side it can be done.
and with ASP and with PHP etc.

an example for ASP:
==============================
<%
Function GetContent(url)
    Dim xmlHttp
    Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
    xml.Open "GET", url, True
    Call xml.Send()

      If xml.readyState <> 4 Then
        xml.waitForResponse 3
    End If
   
     If Err.Number <> 0 Then
    Else
         If (xml.readyState <> 4) Or (xml.Status <> 200) Then
              xml.Abort
              strData = "Problem communicating with remote server..."
         Else
              strData = xml.ResponseText
         End If
    End If
    GetContent = strData
End Function
%>

<%=GetContent("http://oldlook.experts-exchange.com/")%>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
paygoAuthor Commented:
Does anyone have this solution in C# scripting - instead of VB?
0
devicCommented:
I don't have, wait a while I do it.
0
devicCommented:
here an example:

you needd add COM reference: Project --> Add Reference --> COM -->
there find Microsoft.Xml, 5.0 or another version.




then declare it:
=========================
using MSXML2;





and go:
=========================

                  string postData = "";
                  string uriString = "http://www.sembel.net";
                  String strXML ;

                  XMLHTTPClass xmlHTTP = new XMLHTTPClass();

                  xmlHTTP.open("POST", uriString,false,null,null) ;
                  xmlHTTP.send(postData) ;

                  while(xmlHTTP.readyState != 4)
                  {
                  }

                  strXML = (string)xmlHTTP.responseText;
                  
      
0
paygoAuthor Commented:
Hi Devic,

I have 2 other similar questions posted for 1000 points,  
(look up:Server.CreateObject("MSXML2.ServerXMLHTTP")

I tried Http://www.sembel.net using the above code  - this works fine.

I tried Http://www.cnn.com and received this error:

"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>404 Not Found</title>\n</head><body>\n<h1>Not Found</h1>\n<p>The requested URL / was not found on this server.</p>\n<hr />\n<address>Apache Server at www.cnn.com Port 80</address>\n</body></html>\n"

Thanks
0
devicCommented:
maybe the server checks something, e.g. cookie or referrer

check for example:
http://www.bbc.co.uk
0
paygoAuthor Commented:
The server I will access will check to see if Javascript is enabled.

This is why I started out using an Iframe -  thx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.