...

View Full Version : change frame src based on screen res



sweenster
05-30-2005, 12:52 AM
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:


<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?

Single Paradox
05-30-2005, 03:45 AM
<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.

rlemon
05-30-2005, 02:29 PM
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>

Harry Armadillo
05-30-2005, 03:31 PM
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:
<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).

sweenster
05-30-2005, 11:14 PM
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.



<? 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>

Harry Armadillo
05-31-2005, 02:00 AM
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:
<? 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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum