<%@ include file="/testa.jsp"%> <% int idPagina=-1; String autoRedirSmart = "0"; String autoRedirTablet = "0"; String urlSitoSmart = ""; String urlSitoTablet = ""; if ( request.getParameter("idPagina")!=null ){ try{ idPagina = Integer.parseInt(request.getParameter("idPagina")); }catch(Exception e){ } } if (idPagina!=-1){ c = pool.getConnection(); try{ try{ query="select autoredir_smart, url_sitosmart, autoredir_tablet, url_sitotablet from siti_001 where id_pagina_partenza = ? "; pst= c.prepareStatement(query); pst.setInt(1,idPagina); rs=pst.executeQuery(); if (rs.next()){ autoRedirSmart = rs.getString("autoredir_smart"); autoRedirTablet = rs.getString("autoredir_tablet"); urlSitoSmart = rs.getString("url_sitosmart"); urlSitoTablet = rs.getString("url_sitotablet"); } if (autoRedirSmart == null){ autoRedirSmart = "0"; } if (autoRedirTablet == null){ autoRedirTablet = "0"; } if (urlSitoSmart == null){ urlSitoSmart = ""; } if (urlSitoTablet == null){ urlSitoTablet = "0"; } }catch(Exception eMobile){ }finally{ try{ rs.close(); pst.close(); }catch(Exception rspst){ } } }catch(Exception e){ //System.out.println("\n\n#ERROR IN "+request.getServletPath()+"\nMESSAGE: "+e.getMessage()+"\nDETAILS:"); e.printStackTrace(); }finally{ pool.releaseConnection(c); } out.clear(); %> var typeDevice = "desktop"; if (navigator.userAgent!=null){ var userAgentVerify = navigator.userAgent.toLowerCase(); if ( userAgentVerify.indexOf("ipad") != -1 || (userAgentVerify.indexOf("tablet") != -1 && userAgentVerify.indexOf("tablet pc") == -1) || userAgentVerify.indexOf("playbook") != -1 || (userAgentVerify.indexOf("android") != -1 && userAgentVerify.indexOf("mobile") == -1) ){ typeDevice = "tablet"; } if ( userAgentVerify.indexOf("ipod") != -1 || userAgentVerify.indexOf("iphone") != -1 || (userAgentVerify.indexOf("android") != -1 && userAgentVerify.indexOf("mobile") != -1) || userAgentVerify.indexOf("windows phone") != -1 || userAgentVerify.indexOf("windows ce") != -1 || userAgentVerify.indexOf("fennec") != -1 || userAgentVerify.indexOf("maemo") != -1 || userAgentVerify.indexOf("symbian") != -1 ){ typeDevice = "smartphone"; } } <% if ( (autoRedirSmart.equals("1") && (!urlSitoSmart.trim().equals(""))) || (autoRedirTablet.equals("1") && (!urlSitoTablet.trim().equals(""))) ){ %> keepDesk=getCookieDevice("keepDesk"); function setCookieDevice(cookieName,cookieValue,nDays) { var today = new Date(); var expire = new Date(); if (nDays==null || nDays==0) nDays=1; expire.setTime(today.getTime() + 3600000*24*nDays); document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString(); } function getCookieDevice(cookieName) { var theCookie=" "+document.cookie; var ind=theCookie.indexOf(" "+cookieName+"="); if (ind==-1) ind=theCookie.indexOf(";"+cookieName+"="); if (ind==-1 || cookieName=="") return ""; var ind1=theCookie.indexOf(";",ind+1); if (ind1==-1) ind1=theCookie.length; return unescape(theCookie.substring(ind+cookieName.length+2,ind1)); } if( top != null && top.document != null && top.document.referrer!=null ){ if ( top.document.referrer.indexOf("<%=urlSitoSmart%>")!=-1 || top.document.referrer.indexOf("<%=urlSitoTablet%>")!=-1 ) { if(keepDesk!=1){ keepDesk = 1; setCookieDevice("keepDesk",keepDesk,(1/12)); } } } if (navigator.userAgent!=null){ if ( typeDevice != "desktop" ){ <% if (autoRedirSmart.equals("1") && (!urlSitoSmart.trim().equals(""))) { %> if ( typeDevice == "smartphone" ){ if(keepDesk!=1){ top.location.href="<%=urlSitoSmart%>"; } } <% } if (autoRedirTablet.equals("1") && (!urlSitoTablet.trim().equals(""))) { %> if ( typeDevice == "tablet" ){ if(keepDesk!=1){ top.location.href="<%=urlSitoTablet%>"; } } <% } %> } } <% } } %>