Home >Web Front-end >JS Tutorial >JS method of displaying line breaks in alert_javascript skills
The example in this article describes the method of displaying line breaks in alert using JS. Share it with everyone for your reference, the details are as follows:
Let’s first introduce a more complicated method, but this method can be used to distinguish any browser model:
//浏览器类型判定 function getOs() { if(navigator.userAgent.indexOf("MSIE")>0) { return "IE"; //InternetExplor } else if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){ return "FF"; //firefox } else if(isSafari=navigator.userAgent.indexOf("Safari")>0) { return "SF"; //Safari } else if(isCamino=navigator.userAgent.indexOf("Camino")>0){ return "C"; //Camino } else if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){ return "G"; //Gecko } else if(isMozilla=navigator.userAgent.indexOf("Opera")>=0){ return "O"; //opera }else{ return 'Other'; } } function alert_br(){ var os=getOs(); if(os=='FF' || os=='SF'){ //FireFox、谷歌浏览器用这个 alert('第一行 第二行'); }else{ //IE系列用这个 alert('第一行 \n第二行); } } alert_br();
The second one is relatively simple, but it can only easily distinguish IE from other browsers:
function alert_br(){ if(!document.all)//FF/{谷歌浏览器用这个 alert('第一行 第二行'); }else{ //IE系列用这个 alert('第一行 \n第二行); } } alert_br();
I hope this article will be helpful to everyone in JavaScript programming.