SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    May 2006
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Target and alter <iframe> contents from another domain

    Hi everyone,

    I've had a good look around and I'm getting the impression that this isn't possible.

    I want to add some classes to various bits on one of Worldpay's lovely payment iframes so I can make it look something like the site it's sat on.

    This is the original principle I was using, which works when on a page with the same domain.

    Code JavaScript:
    $('#worldpay').load(function(){
    		                    $(this.contentDocument).find('body').html('Test: This frame was modified with js')
     
    });

    Any ideas?

  2. #2
    SitePoint Enthusiast Anthony.Barnes's Avatar
    Join Date
    Aug 2011
    Location
    Canberra, Australia
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the iframe is being sourced through a domain than the current page url then the browser will not let you interact with the content of the iframe in anyway. To get around this the iframe source needs to be on the same domain, if you really want to do this then you can use a server side script to proxy the iframe source through your own domain. This brings it's own risks but allows you to manipulated the contents of the iframe.

    If you want to read more on why browsers disallow this kind of behaviour:
    Cross-site scripting - Wikipedia, the free encyclopedia

  3. #3
    SitePoint Addict
    Join Date
    May 2006
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I'll look into it : )


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
  •