Home > Web Front-end > JS Tutorial > body text

JS method of displaying line breaks in alert_javascript skills

WBOY
Release: 2016-05-16 15:25:00
Original
1447 people have browsed it

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();

Copy after login

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();

Copy after login

I hope this article will be helpful to everyone in JavaScript programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template