1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hey Guest Last month we upgraded BlackHatWorld.com to a new platform - . If you notice anything that requires attention please start a new thread here.
    Dismiss Notice

Can I display different content based on an iframe?

Discussion in 'PHP & Perl' started by OTrap, Dec 18, 2013.

  1. OTrap

    OTrap Jr. VIP Jr. VIP Premium Member

    Joined:
    Jul 12, 2008
    Messages:
    2,280
    Likes Received:
    1,051
    Occupation:
    Internet Marketer ... duh!
    What I currently have is something like this:

    PHP:
    <?php


    if ( window.self === window.top ) { ?>

    <html>not in a frame</html>
    <?php } else { ?>

    <html>in a frame</html>

    <?php ?>
    However, I'm obviously missing something, as it reacts as though it's in an iframe, no matter what.

    I have to be missing something, but I'm curious as to what.
     
  2. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,412
    Likes Received:
    9,796
    You 're confusing things. PHP runs on the server, there is no iframe context there - no "window" object :)

    That 's on the client side (after your server has already sent the content to the browser). At that point, javascript is your scripting option.
     
    • Thanks Thanks x 1
  3. OTrap

    OTrap Jr. VIP Jr. VIP Premium Member

    Joined:
    Jul 12, 2008
    Messages:
    2,280
    Likes Received:
    1,051
    Occupation:
    Internet Marketer ... duh!
    Ah, much obliged, Jazz. You're the man.
     
    • Thanks Thanks x 1
  4. barigain

    barigain Junior Member

    Joined:
    Aug 23, 2012
    Messages:
    100
    Likes Received:
    12
    It's javascript code. Just create HTML page and insert your code between these tags:
    <script type="text/javascript">
    [your_code]
    </script>
     
  5. OTrap

    OTrap Jr. VIP Jr. VIP Premium Member

    Joined:
    Jul 12, 2008
    Messages:
    2,280
    Likes Received:
    1,051
    Occupation:
    Internet Marketer ... duh!
    The catch is that it can't show up in the source code. ;)
     
  6. funque

    funque Newbie

    Joined:
    Dec 27, 2013
    Messages:
    21
    Likes Received:
    1
    It's cross-domain security - you can't get frame content from website on another domain. Only from the same domain!
     
  7. OTrap

    OTrap Jr. VIP Jr. VIP Premium Member

    Joined:
    Jul 12, 2008
    Messages:
    2,280
    Likes Received:
    1,051
    Occupation:
    Internet Marketer ... duh!
    Fair enough. All the domains are owned by me, so I wanted to see if it was possible, but as it doesn't seem to be, that's not a problem.

    Thanks for the help!