Can I Apply Javascript To Pages Through Frames?


This is more just curiosity. But is it possible to apply javascripts to pages that are being displayed in frames? Kind of like how Greasemonkey applies javascript to pages displayed in the browser. Basically so that no matter who visited the web page, whether they had Greasemonkey or not, they would be able to see the web page with my custom javascripts applied. If this is possible, how would I go about doing it?

, , , ,

  1. #1 by Drew at June 4th, 2009

    Well, this is sort of a gray area in terms of browser support, so you might have to try a few different methods to get it to work properly, but yes, it’s possible.
    Say I want to get all of the links in the first frame in the document. I would write something like this (in Firefox, at least):
    var links = document . getElementsByTagName(‘frame’)[0] . contentDocument . getElementsByTagName(‘a’);
    (ignore the spaces, Y!A will truncate the code if they’re not there.)

  2. #2 by Germann A at June 4th, 2009

    You can usually apply styles and views, JavaScript is basically a program that you can run and affect something with…
    Is this what you meant? See cross-site scripting on Google…

(will not be published)
Powered by Yahoo! Answers