如果....否則如果....是不是給在JavaScript如果....否則如果....聲明沒有給出任何輸出在javascript
Acctually我匹配任何輸出navigation.userAgent
JavaScript的字符串與一些預定義的字符串使用If.... Else If.....
聲明,但腳本是長約1.76 MB
該腳本包含一些jquery以及JavaScript代碼在執行時,我沒有得到任何輸出,如果條件爲真如If.... Else If....
聲明中定義代碼塊。請建議一些簡單和工作的解決方案,必須讚賞任何幫助。
編輯01
腳本連接到我的index.html與
<script>
標籤的src
屬性。
實際的代碼塊非常大,它只是該腳本的一小段代碼片段,但超越的代碼與此類代碼完全相似。
$(function(){
var winURL = $("body").attr("winredirection");
var androidURL = $("body").attr("androidredirection");
var mobURL = $("body").attr("mobredirection");
var bbURL = $("body").attr("bbredirection");
if (navigator.userAgent=="Mozilla/5.0 (compatible; U; ABrowse 0.6;Syllable) AppleWebKit/420+ (KHTML, like Gecko)") {
window.location.assign($("body").attr("winredirection"));
}
else if (navigator.userAgent=="Mozilla/5.0 (compatible; ABrowse 0.4; Syllable)") {
window.location.assign($("body").attr("winredirection"));
}
else if (navigator.userAgent=="Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; Acoo Browser 1.98.744; .NET CLR 3.5.30729)") {
window.location.assign($("body").attr("winredirection"));
}
else if (navigator.userAgent=="Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; Acoo Browser 1.98.744; .NET CLR 3.5.30729)"){window.location.assign($("body").attr("winredirection"));}else if (navigator.userAgent=="Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; Acoo Browser; GTB5; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; InfoPath.1; .NET CLR 3.5.30729; .NET CLR 3.0.30618)"){window.location.assign($("body").attr("winredirection"));}else if (navigator.userAgent=="Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SV1; Acoo Browser; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; Avant Browser)"){window.location.assign($("body").attr("winredirection"));}
});
編輯02
我的index.html頁面
<!DOCTYPE html>
<html>
<head>
<title>
Platform Identification using perfect.api.js
</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="perfect.api.js"></script>
</head>
<body winredirection="http://google.com" androidredirection="www.google.com/mobile/android" mobredirection="www.google.com/mobile" bbredirection="www.google.com/mobile/bb">
</body>
</html>
感謝,
API開發
答案使用switch語句或調度陣列 –
@Ed_Heal您可以提供的代碼 –
以及爲什麼問題導致? –