SitePoint Sponsor

User Tag List

Results 1 to 20 of 20
  1. #1
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Getting attribute of element inside an iframe

    I have a document containing an iframe (please don't ask why...), and now I'm trying to access elements/attributes in the document inside that iframe

    Tried code like this:
    Code:
    ...
    var frm = document.getElementById("iframe_id");
    var doc = frm.contentDocument;
    var lnk = doc.getElementById("link_id");
    ...
    Result:
    Error: uncaught exception:
    Permission denied to get property HTMLDocument.getElementById

    And, yes, the src of the iframe is an external document (relevant info?)

    Help!

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just replied to a similar question here, perhaps that will be helpful.

  3. #3
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops... You're asking about iframe - I didn't read the question too good did I. I think I've got something else... brb

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Edit:


    obviously I'm not awake yet


    I think your code is right - esp. for Moz. Must be a security thing.

    Edit:

    I can duplicate the problem - but I don't know what to do about it. I'm really lookin stupid here - I hope someone comes along and rescues me pretty quick
    Last edited by MikeFoster; Oct 9, 2003 at 10:25.

  5. #5
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MikeFoster
    Oops... You're asking about iframe - I didn't read the question too good did I. ...
    Isn't that other question ("Accessing an iframe content through DOM") about an iframe too?

    OK, now I know there are at least 2 persons having the same problem...
    (Not only me feeling stupid)

  6. #6
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  7. #7
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are both the containing document and framed document within the same domain?

    Cross-domain DOM manipulation (even reading) is restricted by all browsers that I'm familiar with.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  8. #8
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by beetle
    Are both the containing document and framed document within the same domain?
    No, different domains

    Quote Originally Posted by jofa
    ...the src of the iframe is an external document (relevant info?)

    Quote Originally Posted by beetle
    Cross-domain DOM manipulation (even reading) is restricted by all browsers that I'm familiar with.
    That explains a lot of things.
    I guess the only (im)possible solution is: Instruct each user how to add both domains to "trusted sites" (and in the Mozilla cases, how to install the Policy Manager add-on)?



    Thank you for the answer, anyway

  9. #9
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ya, sorry to be the bearer of bad news, but with the symptoms you described, that seemed to be the only remaining issue.

    Now that you know, I'm sure it won't take you long to postulate why browser security doesn't allow this.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  10. #10
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    How about bringing the page to you server-side (like with XMLHTTP in ASP), stripping out the unneeded <html>, <body>, etc. tags, and including the content in a <div> instead? Then you can use the regular DOM (childNodes, etc.) to manipulate elements, but will still have a fresh copy of the data in the remote page. It's a lot of extra work but if you really need this it's worth a shot.

  11. #11
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's an interesting idea, Vinnie. I'd be curious to see that in action.

    I think it goes without saying to be mindful of possible legal issues.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  12. #12
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Vinnie and beetle, thanks for the rescue

  13. #13
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hehe, ya. It looks like you jumped into the water with your clothes on
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  14. #14
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and my wallet, and my keys, and my cellphone...

  15. #15
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What are you up to Mike? Changing your avatar everytime you post?
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  16. #16
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by beetle
    I think it goes without saying to be mindful of possible legal issues.
    I wouldn't think that there'd be any more legal issues involved than having the remote site in an iframe in the first place.

  17. #17
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vgarcia
    How about bringing the page to you server-side (like with XMLHTTP in ASP)...
    Yep, that was what I tried after the unsuccessful HTMLDocument.getElementById experience

    Error: uncaught exception: Permission denied to call method XMLHttpRequest.open




    I think I've resigned, sort of



    Legal issues:
    The document inside the iframe is a news ticker from BBC (already checked that it's OK to include it), and the only thing I wanted to change was target="_top" to target="_blank" (and please, no comments on using the target attribute...)

  18. #18
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ya, I think your optionless at this point. Sorry, bud.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  19. #19
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by beetle
    What are you up to Mike? Changing your avatar everytime you post?


    But they're all so sharp... I can't make up my mind...

  20. #20
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wondering: Is there a way to automatically pop up the Policy Manager add-on in Mozilla? (I know, kind of self contradictory, if the user has enabled popup blocking... )


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •