Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
Thread: Can't access frame content
02-29-2012, 04:27 PM #1
- Join Date
- Feb 2012
- Thanked 0 Times in 0 Posts
Can't access frame content
I'm trying to write a little Greasemonkey script (in Firefox) to manipulate the top bar Google Translate produces when translating a site. For example: http://translate.google.com/translat.../www.google.de.
Google has employed traditional HTML frames. According to many websites, I can use something like window.frames.contentDocument to access the first frame. However, this is refusing to work!
I have been debugging this for hours. I have verified that I am indeed running the script from the top-level window (window.parent === window.top), and I am able to manipulate the frames themselves without a problem. When I try something like window.frames.contentDocument.URL, it returns as about:blank (I also get this with the other frame, i.e., frames). I have tried several different methods of getting at that frame, including getElementsByTagName("frame") (which works for manipulating the frame itself, but not for editing the frame's content through contentDocument).
Here's my little script so far. I've included the first part so you can see for yourself that I'm definitely in the top-level window and using the right @include because it works. In this example, the URL returned is "about:blank" (again, I'm in Firefox).
// ==UserScript== // @name GTranslate // @include /^https?://translate\.google\.com/translate\?.*/ // ==/UserScript== // change how the frame is displayed var bar = document.getElementsByTagName("frame"); bar.removeAttribute("noresize"); // manipulate the content inside the frame var gt = bar.contentDocument; alert(bar.URL);