views:

41

answers:

1

I am interested in developing some javascript that resides as browser bookmark that can mine data from nested iframes and AJAX the data back to a remote server. A small collection such scripts would be used to coordinate player stats and attack strategy for a popular online game.

I am a novice javascript programmer and don't know if this is possible. My attempts thus far have failed, although I have authored other javascript code that works great in other applications.

Is it possible that I am violating the same-origin policy? Something is wrong. Code that should work gives me nothing.

Code such as this:

javascript:
 y=document.getElementsByTagName('iframe')[2];
 alert(y.src);

gives me the result one would expect, but when I try to access what I think should be the innerHTML of the iframe, there is no result.

Any ideas?

A: 

It is very likely that you are violating the same-origin policy.

Recall that your scriptlet will be executing javascript in the domain of the currently loaded page. It also runs with the same restrictions imposed on that page, meaning that it is not allowed to access the content of an IFRAME if it contains a page in a different domain.

You are able to access the src property, because that exists on the tag in the page hosting the IFRAME but you won't be able to access much else, including the innerHTML.

Perhaps you could load that document (the one hosted in the iframe) into the browser, and then run your scriptlet against that?

Daniel LeCheminant
I am fairly sure that my application is in violation of the same-origin-policy. I tried loading the iframe in another window or loading the iframe to a variable, but that does not work either. It seems that the page originator has placed some type of key on the iframe link that allows the page to only be sent one time. They have it locked up good! The only other option appears to be cut-and-paste or good old typing in data to a separate form.Thanks for your thoughts.
Dave