Problem Accessing Frame content

7 views
Skip to first unread message

Siju

unread,
Jun 24, 2009, 8:15:28 AM6/24/09
to greasemonkey-users
Hi All,

I want to access the content of a frame and access an anchor to get
the href (so that I can fire it).

The webpage has multiple frames and when I try window.document, it
gives one of the window. I tried top.document to get the frame I
wanted, that worked. But when I access
contentDocument.firstChild.innerHTML on that frame, it gives me the
content, but that is not the content I see when I use DOM Inspector.
In DOM Inspector, I can see the anchor element that I want to access
in the frame(mainFrame).

This is what I use to get the html
top.document.getElementsByName("mainFrame")
[0].contentDocument.firstChild.innerHTML


MORE DETAILS
-------------------------
The webpage I try is
http://epaper.timesofindia.com/Default/Client.asp?Daily=TOIM&login=default&Enter=true&Skin=TOI&GZ=T&AW=1245845695578

You can see the acnhor, it is the next page link

and the anchor tag I want to access is in mainFrame
<A href="/Default/Scripting/ArchiveView.asp?
Daily=TOIM&amp;AppName=1&amp;login=default&amp;Enter=true&amp;Skin=TOI&amp;GZ=T&amp;BaseHref=TOIM
%2F2009%2F06%2F24&amp;AW=1245834196578&amp;Page=3"><IMG border="0"
title="Next Page" alt="Next Page" src="/Default/Layout/Images/TOI/
Buttons/nextPage.gif"/></A>



qufighter

unread,
Jun 29, 2009, 5:55:46 PM6/29/09
to greasemonkey-users
Tons of ways to do this, but are you sure you need to do all that?
Script should auto run on each iFrame normally, so I think this
applies to regular frames as well although I could be mistaken. Make
sure you have the correct include for the URL of the frame you are
trying to access

http://epaper.timesofindia.com/Default/Scripting/ArchiveView.asp?Daily=TOIM&login=default&Enter=true&Skin=TOI&GZ=T&AW=1246311215265&AppName=1
Try this for testing - right click - this frame -> show only this
frame, will simplify things.

Forget inner HTML for something like this using XPATH makes perfect
sense...

//img[@title='Next Page']

Returns both of the next page button's images (there is a smaller one
in the red bar, the second result is the one you were tlking about I
think)

That string of xpath will get you the nextButton image, so if you do a
parentNode on the result (you can probably just use the single result
option for document.evaluate) there are tons of examples of this out
there, but the parentNode of the image is the link you want, since the
image has the nice alt and or title "Next Page" just match that,
otherwise it gets more complex. Some examples of how to use
document.evaluate http://userscripts.org/topics/26131
https://developer.mozilla.org/en/DOM/document.evaluate

On Jun 24, 8:15 am, Siju <siju.mat...@gmail.com> wrote:
> Hi All,
>
> I want to access the content of a frame and access an anchor to get
> the href (so that I can fire it).
>
> The webpage has multiple frames and when I try window.document, it
> gives one of the window. I tried top.document to get the frame I
> wanted, that worked. But when I access
> contentDocument.firstChild.innerHTML on that frame, it gives me the
> content, but that is not the content I see when I use DOM Inspector.
> In DOM Inspector, I can see the anchor element that I want to access
> in the frame(mainFrame).
>
> This is what I use to get the html
> top.document.getElementsByName("mainFrame")
> [0].contentDocument.firstChild.innerHTML
>
> MORE DETAILS
> -------------------------
> The webpage I try ishttp://epaper.timesofindia.com/Default/Client.asp?Daily=TOIM&login=de...
Reply all
Reply to author
Forward
0 new messages