Home >Web Front-end >JS Tutorial >JS method of displaying line breaks in alert_javascript skills

JS method of displaying line breaks in alert_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:25:001485browse

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.

Statement:
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