Can I display different content based on an iframe?

 

Results 1 to 7 of 7
What I currently have is something like this: PHP Code: <?php if (  window . self  ...
  1. #1
    OTrap's Avatar
    OTrap is offline Elite Member
    Join Date
    Jul 2008
    Posts
    2,205
    Thanks
    351
    Thanked 956 Times in 462 Posts

    Default Can I display different content based on an iframe?

    What I currently have is something like this:

    PHP Code:
    <?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. #2
    jazzc's Avatar
    jazzc is online now Programming & Web Design Moderator black hat forumsblack hat forumsblack hat forums
    Join Date
    Jan 2009
    Posts
    2,025
    Thanks
    5,545
    Thanked 6,261 Times in 2,240 Posts

    Default Re: Can I display different content based on an iframe?

    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.

  3. The Following User Says Thank You to jazzc For This Useful Post:

    OTrap (12-17-2013)

  4. #3
    OTrap's Avatar
    OTrap is offline Elite Member
    Join Date
    Jul 2008
    Posts
    2,205
    Thanks
    351
    Thanked 956 Times in 462 Posts

    Default Re: Can I display different content based on an iframe?

    Ah, much obliged, Jazz. You're the man.

  5. The Following User Says Thank You to OTrap For This Useful Post:

    jazzc (12-17-2013)

  6. #4
    barigain is offline Junior Member
    Join Date
    Aug 2012
    Posts
    100
    Thanks
    5
    Thanked 12 Times in 12 Posts

    Default Re: Can I display different content based on an iframe?

    It's javascript code. Just create HTML page and insert your code between these tags:
    <script type="text/javascript">
    [your_code]
    </script>

  7. #5
    OTrap's Avatar
    OTrap is offline Elite Member
    Join Date
    Jul 2008
    Posts
    2,205
    Thanks
    351
    Thanked 956 Times in 462 Posts

    Default Re: Can I display different content based on an iframe?

    The catch is that it can't show up in the source code.

  8. #6
    funque is offline Newbies
    Join Date
    Dec 2013
    Posts
    21
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Can I display different content based on an iframe?

    Quote Originally Posted by OTrap View Post
    The catch is that it can't show up in the source code.
    It's cross-domain security - you can't get frame content from website on another domain. Only from the same domain!

  9. #7
    OTrap's Avatar
    OTrap is offline Elite Member
    Join Date
    Jul 2008
    Posts
    2,205
    Thanks
    351
    Thanked 956 Times in 462 Posts

    Default Re: Can I display different content based on an iframe?

    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!


Similar Threads

  1. Replies: 1
    Last Post: 09-15-2013, 07:00 AM
  2. Is it possible to display referring url in an iframe?
    By mightybh in forum General Programming Chat
    Replies: 0
    Last Post: 02-18-2012, 06:39 PM
  3. Any way to display a random YouTube video based on your keyword?
    By mightybh in forum General Scripting Chat
    Replies: 0
    Last Post: 05-29-2011, 06:14 PM
  4. $5 to get my scrollbar to display with my iframe
    By bindasj in forum Hire a Freelancer
    Replies: 0
    Last Post: 01-05-2010, 05:09 AM
  5. how to display ads based on content or tags?
    By zongoneri in forum Blogging
    Replies: 10
    Last Post: 08-09-2009, 05:40 AM

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
  •  




BlackHatWorld on Twitter BlackHatWorld on FaceBook


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98