SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    frame detection script

    Hello,

    I need a script that detects if the browser is viewing a certain page within a frameset, and if it is not, to open the page through frameset instead.

    For example if the site has a mainframe and a navframe, if someone goes to the mainframe from a search engine, the script will open up the frameset html so the navframe shows up too.

    If someone can help me with this I would appreciate it muchly.

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well say you have content.html but index.html is the framepage into which it would normally be loaded.
    In content.html just say:

    if (window.location == this.location) window.location='index.html';

    .oO ( something like that - i think )

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you wanting to load the requested page into the frameset? Or just pull up the default frameset?
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's some cut and paste code I did about a year ago that handles what I think you are after. First, the frameset source code:
    Code:
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <script language="javascript">
       var content = "body.htm";
       var theRefer = document.referrer;
       var okLink = false;
       if (theRefer.indexOf(parent.location.host) != -1)
       	theRefer = "";
       if (theRefer == "")
    	okLink = true;
       if (document.cookie != "" && okLink == true && parent.location.href.indexOf('.htm') != -1)
    	content = document.cookie;
    </script>
    
    </head>
    
    
    <script>
    
    document.write('<frameset rows="105,*,60" frameborder="NO" border="0" framespacing="0" cols="*">');
    document.write('<frame name="topFrame" scrolling="NO" noresize src="top.htm" frameborder="NO" >');
    document.write('<frameset cols="212,*" frameborder="NO" border="0" framespacing="0" rows="*"> ');
    document.write('<frame name="leftFrame" scrolling="NO" noresize src="side.htm" frameborder="NO">');
    
    // This is the line that does the work
    document.write('<frame name="mainFrame" src=' + content + ' frameborder="NO">');
    // This is the line that does the work
    
    document.write('</frameset>');
    document.write('<frame name="bottomFrame" src="bottom.htm" scrolling="NO" noresize frameborder="NO">');
    document.write('</frameset>');
    
    </script>
    
    <noframes>
    <body bgcolor="#FFFFFF" text="#000000">
    </body>
    </noframes>
    </html>
    Next, is the sourcecode for 'noframes.js'
    Code:
    var framesetName = "index2.htm" // Enter the name of your framset page here
    
    if (parent.frames[0] == null){
    
    	var foundPointer = false;
    	var fullUrl = parent.location.href;
    	
    	if (fullUrl.indexOf(framesetName) == -1) 
    		{
    		var lengthOfUrl = fullUrl.lastIndexOf('/');
    		var topicUrl = fullUrl.substring(lengthOfUrl+1);
    		window.document.cookie = topicUrl;
    		foundPointer = true
    		}
    	
    	if (foundPointer == true)
    	window.location.href = framesetName;	
    }
    On every page that you want to 'jump into' the frameset, simplay include the 'noframes.js' file
    Code:
    <script language="javascript" src="js/noframes.js"></script>
    You can see this code working at www.medivisuals.com. Visit this page http://www.medivisuals.com/prof.htm to see what happens (no longer at prof.htm, but at frameindex.htm with prof.htm in the contentFrame)

    This code is old, so I'm not sure of it's compatiblity from a browser standpoint...
    Last edited by beetle; Jul 23, 2002 at 11:50.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey there again. I was rummaging around in my dusty computer files and found this .js file for handling frames.
    This is more recent (slightly) than the code I put in my above post, and has built-in documentation.

    http://www.peterbailey.net/js/superframes.js

    Enjoy.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





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
  •