jquery - If.... Else If.... statement is not giving any Output in javascript -
if.... else if.... not giving output in javascript
acctually matching navigation.useragent
string of javascript predefined strings using if.... else if.....
statement script long 1.76 mb
script contains jquery javascript codes @ time of execution didn't output if condition true defined in if.... else if....
statement code block. please suggest simple , working solution must appreciated.
edit 01
the script attached index.html
<script>
tag'ssrc
attribute.
the actual code block large small code snippet of script code beyond similar one.
$(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, 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"));} });
edit 02
my index.html page
<!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>
thanks,
api developer
firstly recommend not manually parse user agent strings code can become mess maintain way doing whole bunch of if/else if statements. use library this: https://github.com/faisalman/ua-parser-js. using it's getos() function determine operating system being used or it's other functions determine device being used rather matching specific user agents.
the code have looks fine, can't test don't have of browsers have in user agent strings provided in example recommend doing using library linked above:
var parser = new uaparser(); var os = parser.getos(); if(os.name == "windows") { $("body").attr("winredirection"); } //other operating systems and/or devices go below.
Comments
Post a Comment