Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 20th, 2004, 05:25 AM
Authorized User
 
Join Date: Apr 2004
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem in getting innerText of iframe

Hi:

I have a problem in getting innerText of iframe.
I use this script:

var inText = document.getElementById("f1").document.body.innerT ext;
alert(inText);
// After using this script i receive innerText of whole page, but not iframe.

Then i use this:
var inText = f1.document.body.innerText;
alert(inText);
// After using this i receive error message "Access Denied"

Then i use this:
var inText = document.frames("f1").document.body.innerText;
alert(inText);
// After using this i receive same error message "Access Denied"

Can any body tell me what is going wrong?

Thanks
Burhan
 
Old August 20th, 2004, 05:47 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Burhan,

Is the content of the iframe in the same domain as the page that contains it?

If not, that is why you are getting "Access Denied".

HTH,

Chris

 
Old August 21st, 2004, 12:13 AM
Authorized User
 
Join Date: Apr 2004
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for reply.

My iframe code is look like this:

<iframe name="f1" src="http://www.myhomepage.com" width="500" height="500">
Your browser does not support inline frames or is currently configured not to display inline frames.</iframe>


if that is the problem, then is here no way to get the innerText of http://www.myhomepage.com?

Burhan

 
Old August 23rd, 2004, 03:35 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

The innerText of an iframe is the text in between the tags, not the document content of the frame. If the URL of the iframe is from the same server as the enclosing page and uses the same protocol you can access HTML content by:
Code:
var oFrame = window.top.frames["f1"];
var oDoc = oFrame.document;
alert(oDoc.documentElement.outerHTML);
Using document.getElementById enables you to get the element of the iframe, not the window itself.

--

Joe
 
Old August 23rd, 2004, 10:59 AM
Authorized User
 
Join Date: Apr 2004
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank Joefawcett for your comment.

But the problem is that, the URL of iframe is from another server.

Now how to access the innerText or outerHTML?


From
Burhan

 
Old August 23rd, 2004, 12:51 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

From everything I've heard, this is not possible, and I've seen this question many times :-(

Snib

<><
 
Old August 24th, 2004, 10:55 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You could, assuming users allow it, instantiate the MsXml2.XmlHttp.4.0 class and grab the web page. There are examples in the Xml 4 parser sdk available from

http://msdn.com/xml

The link is on the right hand side.

Contrary to its name you can grab ordinary pages of HTML, not just XML ones.

If this is not good enough you would have use a proxy on the server to fetch the data.


--

Joe (Co-author Beginning XML, 3rd edition)





Similar Threads
Thread Thread Starter Forum Replies Last Post
datagrid, innertext, javascript, database update vsr ASP.NET 1.0 and 1.1 Professional 1 November 6th, 2007 05:54 PM
iframe refresh problem haieshwar Javascript 3 January 17th, 2007 06:59 PM
IFRAME Problem NEO1976 Javascript 1 July 21st, 2006 05:11 PM
IFRAME Problem NEO1976 Javascript How-To 0 July 10th, 2006 10:13 AM
Cascading iframe problem nerssi HTML Code Clinic 0 June 13th, 2005 04:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.