/ / Come posso rilevare il browser usando jQuery - jquery, html

Come posso rilevare il browser usando jQuery - jquery, html

Ho provato tutte le soluzioni dal link sottostante ma non riuscivo a farlo funzionare. Come posso rilevare il tipo di browser usando jQuery?

$(document).ready(function(e) {
$.browser.chrome = /chrom(e|ium)/.test(navigator.userAgent.toLowerCase());
if($.browser.chrome){
alert(1);
//this work well
}
else if(//the browser is IE){alert(2);}
else if(//the browser is Firefox){alert(3);}

)};

Grazie.

risposte:

0 per risposta № 1

$ .browser è deprezzato quindi potresti dover usare il plugin migrate come menzionato in: https://api.jquery.com/jquery.browser/

Il controllo del browser potrebbe non essere più pertinente, dai uno sguardo a: http://webaim.org/blog/user-agent-string-history/

È possibile utilizzare window.navigator.appVersion se si desidera rilevare ancora il browser.

Potrei vedere window.navigator.appVersion restituito di seguito a me:

IE: "5.0 (Windows NT 6.1; WOW64; Trident / 7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDC; .NET4.0C; .NET4 .0E; GWX: RESERVED; rv: 11.0) come Gecko "

Mozilla: "5.0 (Windows)"

Cromo: "5.0 (Windows NT 6.1; WOW64) AppleWebKit / 537.36 (KHTML, come Gecko) Chrome / 53.0.2785.116 Safari / 537.36"