2012-07-21 80 views
0

我試圖使用移動重定向腳本的jQuery的版本,這裏提供 - http://detectmobilebrowsers.com/如果VAR條件重定向到URL

簡單指令說,「jQuery.browser.mobile會如果瀏覽器是真移動設備「

我正在創建if條件來重定向頁面,但我是一個新手。幫助將不勝感激。

var mobile = "jQuery.browser.mobile"; 
var url = "http//domain.com/mobile"; 

$(document).ready(function() { 
    if (mobile = true) { 
     $(location).attr('http://domain.com/mobile',url); 
    } 
}); 
+1

只需在第一行刪除'jQuery.browser.mobile'周圍的引號。它應該工作 – 2012-07-21 20:17:27

回答

0
if (mobile = true) { 

應該

if (mobile == true) { 

或更好,但

if (mobile) { 
2
if(jQuery.browser.mobile) { 
    location.href = 'http://domain.com/mobile'; 
} 

但是,你需要學習JavaScript首先。您發佈的代碼清楚地表明您不瞭解該語言的基礎知識。