1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Render different HTML if page is framed ...

Discussion in 'HTML & JavaScript' started by OTrap, Dec 18, 2013.

  1. OTrap

    OTrap Jr. VIP Jr. VIP

    Joined:
    Jul 12, 2008
    Messages:
    2,282
    Likes Received:
    1,051
    Based on the code, I assume you can see what I'm trying to do. However, I'm pretty new to Javascript, so any help is appreciated.

    HTML:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
    
    <script language="JavaScript">
    if ( top.location.href!= window.location.href ) { 
    
    <head>Page 1</head>
    <bode>not in a frame</body>
    
    } else {
    
    <head>Page 2</head>
    <bode>in a frame</body>
    
    }
    
    </script>
    
    </html>
    Thanks.
     
  2. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,143
    Javascript doesn't mingle with HTML in the same way as PHP.

    Do this - put the content you want for case a in a div with id "case1" and the content for the other page inside a div with id "case2". With that javascript if you will make the appropriate div visible and the other hidden.

    Obviously this is meaningful if you are trying to display content for users, not for bots.