← Desenvolvimento

Scripts para redireccionar de acordo com a resolução

Lida 4457 vezes

Offline

fpware 
Fundador
Mensagens 15318 Gostos 7
Troféus totais: 38
Trófeus: (Ver todos)
Linux User Mobile User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5

É possível redireccionar um visitante para uma página, ou para outra de acordo com a resolução do seu ecran.

Deixo aqui dois scripts que ajudam nessa tarefa.

1. O mais simples:

Código: [Seleccione]
<SCRIPT language="JavaScript">
<!--
if ((screen.width>=1024) && (screen.height>=768))
{
 window.location="altaresolucao.html";
}
else
{
  window.location="baixaresolucao.html";
}
//-->
</SCRIPT>


Isto quer dizer que, caso a resolução do monitor do visitante seja superior, ou igual a 1024x768, ele será redireccionado para a página "altaresolucao.html"; caso seja inferior a 1024x768 ele será redireccionado para a página "baixaresolucao.html".

2. Este é um pouco mais complexo:

Colocar entre <head> e </head>

Código: [Seleccione]
<script language="JavaScript1.2">
function ScreenGoToURL(Big,Medium) {
var screen_height = screen.height;
var screen_width = screen.width;
var buffer = (document.all || document.layers ||documentGetElementByID) ? 30 : 48;
if (screen_height >= 768) {
   screen_width = 1024;
   screen_height = 768;
    var window_width = 1024-12;
     var window_height = 768-buffer;
     var window_top = 0;
     var window_left = 0;
     window.open(Little,'','resizable=no,status=yes,width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + '');

} else {
   screen_width = 800;
   screen_height = 600;
   var window_width =  800-12;
    var window_height = 600-buffer;
   var window_top = 0;
    var window_left = 0;
    window.open(Medium,'','resizable=no,status=yes,width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + '');

}
}
</script>


A colocar na TAG Body:

Código: [Seleccione]
<BODY onLoad="ScreenGoToURL('1024x768.html','800x600.html')">

Este é um pouco mais complexo, a vantagem é que é expansível, por exemplo poderá colocar mais um:

Código: [Seleccione]
} else {
   screen_width = 640;
   screen_height = 480;
   var window_width =  640-12;
    var window_height = 480-buffer;
   var window_top = 0;
    var window_left = 0;
    window.open(Little,'','resizable=no,status=yes,width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + '');


Adicionando "Little" a:

Código: [Seleccione]
function ScreenGoToURL(Big,Medium,Little)

e na tag body:

Código: [Seleccione]
<BODY onLoad="ScreenGoToURL('1024x768.html','800x600.html')">

Espero que ajude  8)