...

View Full Version : Refresh the page once detect resolution changes



shadyy
10-10-2003, 11:10 PM
Hi,

I was wanna to have a script that can make a refresh to the page once it detect change in resolution.
I mean script make detect for resolution every second, and once changed , it make refresh itself...
By posting in DevShed, a gr8 member replied with a script he made as follows:

code:----------------------------------------------------------
<script type="text/javascript"><!-- webmasta

var br =(navigator.appName =='Netscape')? 0 : 1;
var olRes =(br)? screen.availWidth : screen.width;

function chekRes() {
var chRes =(br)? screen.availWidth : screen.width;
if (olRes != chRes) { location =location; }
}
//--></script>

<body onload="setInterval('chekRes()', 1000);">
--------------------------------------------------------------
But it still not workin

Hope I could find a solution for that soon

Thanks

Shady

Willy Duitt
10-10-2003, 11:40 PM
Not really sure what you are asking,
or what exactly doesn't work in your script.

But, the reloadIt() function I added should
reload the page once if your arguements are valid.

<script type="text/javascript">
<!--
function reloadIt() {
isNew = self.location.href
if(!isNew.match('#')) {
self.location.replace(isNew + '#')
}
}

var br =(navigator.appName =='Netscape')? 0 : 1;
var olRes =(br)? screen.availWidth : screen.width;

function chekRes() {
var chRes =(br)? screen.availWidth : screen.width;
if (olRes != chRes){
reloadIt();
}
}

//-->
</script>

....Willy

shadyy
10-11-2003, 10:14 AM
Thanks

I tried it also but no way, about the problem:

check www.ifcalex.com/xetronix

I made a text layer that work with swap image in the main page, this work good in all resolutions
But when you open the page and change the resolution without close the page, the text layer position not refreshed.
So I was lookin for kind of script that can detect the change of resolution so it make a auto refresh 2 solve the issue.
Hope we can work around it 2 make it happen ;)
Thanks again

Shady

glenngv
10-11-2003, 11:18 AM
the browser has to remember the old resolution...


var br =(navigator.appName =='Netscape')? 0 : 1;
var olRes = (br) ? screen.availWidth : screen.width;
var savedOlRes;
if (top.name)
savedOlRes = top.name;
else {
savedOlRes = olRes;
top.name = olRes;
}

function chekRes() {
var chRes = (br) ? screen.availWidth : screen.width;
if (savedOlRes != chRes) location.reload();
}

<body onload="setInterval('chekRes()',1000)">

shadyy
10-11-2003, 01:08 PM
Thanks for join us...
I tried your code, still page don't refresh when resolution changed!!!
Check updated code at www.ifcalex.com/xetronix


Shady

glenngv
10-11-2003, 01:29 PM
I forgot to update the remembered screen width, that's why when you change the resolution, the page will reload endlessly.



var olRes = screen.width;
var savedOlRes;
if (top.name)
savedOlRes = top.name;
else {
savedOlRes = olRes;
top.name = olRes;
}

function chekRes() {
var chRes = screen.width;
if (savedOlRes != chRes) {
top.name = chRes;
location.reload();
}
}


You can just use screen.width.

shadyy
10-11-2003, 07:27 PM
I tried it on www.ifcalex.com/xetronix

I was on 1024 res then changed to 800 and it refreshed, but there is two issue:

1- When the page refreshed, it keep refresh every second, while the res 800 didn't changed, so we wanna make it stop and only detect check till the resolution change again.

2- Due to the first issue, when return back from 800 to 1024, refresh not workin.

Thanks alot

A1ien51
10-11-2003, 10:21 PM
How many people change their resolution as they surf the web???? I doubt anyone does really unless they are really bored

glenngv
10-13-2003, 09:30 AM
Originally posted by shadyy
I tried it on www.ifcalex.com/xetronix

I was on 1024 res then changed to 800 and it refreshed, but there is two issue:

1- When the page refreshed, it keep refresh every second, while the res 800 didn't changed, so we wanna make it stop and only detect check till the resolution change again.

2- Due to the first issue, when return back from 800 to 1024, refresh not workin.

Thanks alot

I already fixed that in the 2nd code I posted. Did you try it?

shadyy
10-13-2003, 11:45 PM
Yes I tried , view source yourself ;)

The two issue remain till now, thnx 4 check

glenngv
10-14-2003, 02:11 AM
Originally posted by glenngv
I forgot to update the remembered screen width, that's why when you change the resolution, the page will reload endlessly.



var olRes = screen.width;
var savedOlRes;
if (top.name)
savedOlRes = top.name;
else {
savedOlRes = olRes;
top.name = olRes;
}

function chekRes() {
var chRes = screen.width;
if (savedOlRes != chRes) {
top.name = chRes;
location.reload();
}
}


You can just use screen.width.

You didn't use the updated code I posted. :rolleyes:
Did you notice the added line (top.name = chRes) in the chekRes() funtion?
I even said that you can just use screen.width.
Is my 2nd post invisible? :rolleyes: :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum