Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 20th, 2004, 05:25 AM
Authorized User
 
Join Date: Apr 2004
Location: Lahore, , Pakistan.
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
Reply With Quote
  #2 (permalink)  
Old August 20th, 2004, 05:47 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
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

Reply With Quote
  #3 (permalink)  
Old August 21st, 2004, 12:13 AM
Authorized User
 
Join Date: Apr 2004
Location: Lahore, , Pakistan.
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

Reply With Quote
  #4 (permalink)  
Old August 23rd, 2004, 03:35 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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
Reply With Quote
  #5 (permalink)  
Old August 23rd, 2004, 10:59 AM
Authorized User
 
Join Date: Apr 2004
Location: Lahore, , Pakistan.
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

Reply With Quote
  #6 (permalink)  
Old August 23rd, 2004, 12:51 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
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

<><
Reply With Quote
  #7 (permalink)  
Old August 24th, 2004, 10:55 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:02 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.