SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot matches's Avatar
    Join Date
    Aug 2006
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    walk the dom to a div within an iframe - impossible...right?

    Hey there,

    I have an iframe on a page of ours. I would like to change the css for certain elements through the DOM but from what I gather this is impossible. Is that correct? Is there any work round at all? I have acces to the CSS file. Its just called from within iframe.

    Thanks for your help

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have access to any content that comes from the same domain as the page that contains the iframe- any properties of documents from remote sites are off limits to javascipt.

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2007
    Location
    Gothenburg, Sweden
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try something like this (using the iframes name attribute):

    Code:
    <iframe name="my_iFrame" src="somePage.html"></iframe>
    
    <a href="#" onclick="frames['my_iFrame'].document.body.style.background = 'red';">Change Background</a>
    <a href="#" onclick="frames['my_iFrame'].document.getElementById('someNode').style.color = 'green';">Change some color</a>

  4. #4
    SitePoint Zealot matches's Avatar
    Join Date
    Aug 2006
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well it's a sub domain of our site. An when I try to access the iframe through the dom I get the folowing error:

    uncaught exception: Permission denied to get property HTMLDocument.getElementById

    Sounds like I don't access to an ifram within a subdomain, maybe?

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2007
    Location
    Gothenburg, Sweden
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm, could you try something like this before manipulating the iframes DOM?

    Code:
    document.domain = 'bar.com'; //bar.com is the iframes domain name
    ...or perhaps:
    Code:
    frames['my_iFrame'].document.domain = 'foo.com';//foo.com is the current documents domain name

  6. #6
    SitePoint Addict jlisec01's Avatar
    Join Date
    Nov 2006
    Location
    MI
    Posts
    331
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I prefer using div's instead, probably better off than using iframe, builds up to much history. but just a suggestion.


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
  •