Shamil.
12-26-2010, 10:00 PM
You can make your forum produce an unobtrusive javascript alert whenever your community members view your site from a mobile device, such as an Apple iPhone/iPod, Android-based device or Symbian-based device by entering a little javascript in your forum's header or footer template.
function detectMobilePlatform() {
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
if (confirm("The message you want them to see.")) {
document.cookie = "mobile_redirect=false";
window.location = "http://link/to/page";
} else {
setNoRedirect();
}
} else if(navigator.userAgent.match(/android/i)) {
if (confirm("The message you want them to see.")) {
document.cookie = "mobile_redirect=false";
window.location = "http://link/to/page";
} else {
setNoRedirect();
}
} else if((navigator.userAgent.match(/Symbian/i)) || (navigator.userAgent.match(/Nokia/i))) {
if (confirm("The message you want them to see.")) {
document.cookie = "mobile_redirect=false";
window.location = "http://link/to/page";
}
}
function setNoRedirect() {
var date = new Date();
var days = 30;
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+ date.toGMTString();
document.cookie = "mobile_redirect=false" + expires;
}
detectMobilePlatform()
If you are placing this in the footer, place it just before the </body> closing tag. In the header, place it just before the <body> tag. For site speed and optimisation, I recommend you place the code in the footer.
Replace the message with whatever message you want your forum members to see, and replace the URL to the resource you want them to see when they click ok on the mobile device.
function detectMobilePlatform() {
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
if (confirm("The message you want them to see.")) {
document.cookie = "mobile_redirect=false";
window.location = "http://link/to/page";
} else {
setNoRedirect();
}
} else if(navigator.userAgent.match(/android/i)) {
if (confirm("The message you want them to see.")) {
document.cookie = "mobile_redirect=false";
window.location = "http://link/to/page";
} else {
setNoRedirect();
}
} else if((navigator.userAgent.match(/Symbian/i)) || (navigator.userAgent.match(/Nokia/i))) {
if (confirm("The message you want them to see.")) {
document.cookie = "mobile_redirect=false";
window.location = "http://link/to/page";
}
}
function setNoRedirect() {
var date = new Date();
var days = 30;
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+ date.toGMTString();
document.cookie = "mobile_redirect=false" + expires;
}
detectMobilePlatform()
If you are placing this in the footer, place it just before the </body> closing tag. In the header, place it just before the <body> tag. For site speed and optimisation, I recommend you place the code in the footer.
Replace the message with whatever message you want your forum members to see, and replace the URL to the resource you want them to see when they click ok on the mobile device.