Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    Scotland
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts

    change frame src based on screen res

    I'm using a frame to mask my URL, but I want to take this a step further and change the frame src depending on the screen resolution - example: page.php?res=800x600 or page.php?res=1024x768.. you get the idea.

    here is the code I have:
    Code:
    <META NAME="description" CONTENT="WEBSITE.com">
    <META NAME="keywords" CONTENT="">
    </HEAD>
    <FRAMESET border=0 rows="100%,*" frameborder="no" marginleft="0" margintop="0" marginright="0" marginbottom="0">
    
    <script type="javascript">
    response.write('<frame src="http://www.sweenster.co.uk/fstudent/index.php?res='+screen.width+'x'+screen.height+'" scrolling=auto frameborder="no" border=0 noresize>');
    </script>
    
    <frame topmargin="0" marginwidth=0 scrolling=no marginheight=0 frameborder="no" border=0 noresize>
    </FRAMESET>
    </HTML>
    I'm not too hot with javascript so I dont know if what i've done actually makes sense or not.
    If what I have is a pile of nonsense (quite likely!) then has anyone any ideas on how to achieve this?
    My body's a temple... and like those ancient Greek ones it's a ruin
    sweenster.co.uk

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Posts
    525
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <script>

    function screenRes() {

    if(screen.height==600||screen.width==800) {
    document.getElementById('Iframe').src="page.php?res=800x600";
    }
    else if(screen.height==768||screen.width==768) {
    document.getElementById('Iframe').src="page.php?res=1024x768";
    }
    }
    </script>

    <body onload="screenRes();">

    <iframe id="Iframe" src="" height="300px" width="300px"></iframe>

    </body>




    That on the lines of what you're looking for? Sorry I didn't read your whole code lol.
    Single Paradox
    My Site (Under construction)

    Not too bad for a 15 year old

  • #3
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    he wants frames i think.

    I couldn't get it to work with JS (the JS wasn't being rendered come runtime) SO, if you can use a server side lang like php::



    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <FRAMESET border=0 rows="50%,*" frameborder="no" marginleft="0" margintop="0" marginright="0" marginbottom="0">

    <?

    echo '<frame src="http://www.google.ca" frameborder="no" scrolling=no noresize marginwidth=0 marginheight=0 topmargin="0" border=0>';

    ?>
    <frame src="http://www.rlemon.com" frameborder="no" scrolling=no noresize marginwidth=0 marginheight=0 topmargin="0" border=0>
    </FRAMESET><noframes></noframes>
    </html>
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The problem is that document.write (not response.write) writes to the documents body. But a frameset page doesn't have (and can't have) a body.

    You want something like this in the head of the frameset page:
    Code:
    <script type='text/javascript'>
    setTimeout('init()',10);
    function init(){
      if(document && document.documentElement && document.documentElement.childNodes && document.documentElement.childNodes[1].childNodes)
        document.documentElement.childNodes[1].childNodes[0].src+="?res="+screen.width+"x"+screen.height;
      else
       setTimeout('init()',10);
      }
      </script>
    This would check every 10 milliseconds to see if enough of the frameset has been parsed to allow appending your information to the src of the target frame. As a bonus, using a standard, valid frameset definition allow the non-javascript people to use your page (with the default content).

  • #5
    Regular Coder
    Join Date
    Sep 2002
    Location
    Scotland
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That code you suggested is ideal for what I'm looking for.. unfortunately it doesnt want to work - I think it may be something to do with my frameset HTML/PHP code which i've included below.

    Code:
    <? print('<?xml version="1.0" encoding="UTF-8"?>'); ?>
    <!DOCTYPE html 
         PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    
    <link rel="stylesheet" type="text/css" href="style1.css"/>
    
    <script type='text/javascript'>
    setTimeout('init()',10);
    function init(){
      if(document && document.documentElement && document.documentElement.childNodes && document.documentElement.childNodes[1].childNodes)
        document.documentElement.childNodes[1].childNodes[0].src+="&amp;res="+screen.width+"x"+screen.height;
      else
       setTimeout('init()',10);
      }
    </script>
    
    <title>page title here</title>
    </head>
    <frameset border=0 rows="100%,*" frameborder="no" marginleft="0" margintop="0" marginright="0" marginbottom="0">
    <frame src="index1.php?refr=<?=base64_encode(getenv("HTTP_REFERER"))?>" scrolling=auto frameborder="no" border="0" noresize>
    <frame topmargin="0" marginwidth="0" scrolling="no" marginheight="0" frameborder="no" border="0" noresize>
    </frameset>
    </html>
    My body's a temple... and like those ancient Greek ones it's a ruin
    sweenster.co.uk

  • #6
    Regular Coder
    Join Date
    Feb 2005
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Mmmm, that's what happens when the coffee-maker isn't working. Finding the frame through a chain of .childNodes[] is possible, but tends to break when anything is changed. In this case, your index numbers would be different than mine because I tested with the framset and frames on one line, no line-breaks or spaces.

    Anyway a better way to have done it would be to give the frame an id. Eh, better late than never to think of that:
    Code:
    <? print('<?xml version="1.0" encoding="UTF-8"?>'); ?>
    <!DOCTYPE html 
         PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    
    <link rel="stylesheet" type="text/css" href="style1.css"/>
    
    <script type='text/javascript'>
    setTimeout('init()',10);
    function init(){
      if(document.getElementById("theOneToChange"))
        document.getElementById("theOneToChange").src += "&amp;res="+screen.width+"x"+screen.height;
      else
       setTimeout('init()',10);
      }
    </script>
    
    <title>page title here</title>
    </head>
    <frameset border=0 rows="100%,*" frameborder="no" marginleft="0" margintop="0" marginright="0" marginbottom="0">
    <frame id="theOneToChange" src="index1.php?refr=<?=base64_encode(getenv("HTTP_REFERER"))?>" scrolling=auto frameborder="no" border="0" noresize>
    <frame topmargin="0" marginwidth="0" scrolling="no" marginheight="0" frameborder="no" border="0" noresize>
    </frameset>
    </html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •