This article mainly introduces how to implement line breaks in alert in JS. The example analyzes two implementation techniques for implementing line breaks in alert, which is very simple and practical, for more information about how to use JavaScript to display line breaks in alert, see the following example. We will share this with you for your reference. The details are as follows:
First, we will introduce a complicated method, but this method can be used to distinguish all types of browsers at will:
// 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 ') {// use this alert in FireFox and Google browsers ('line 1 and line 2 ');} else {// this alert is used by the IE series ('line 1 \ n line 2);} alert_br ();
The second method is relatively simple, but it can only be divided into IE and other browsers:
Function alert_br () {if (! Document. all) // FF/{Google Chrome uses this alert ('line 1, line 2 ');} else {// this alert is used by the IE series ('line 1 \ n line 2);} alert_br ();
I hope this article will help you design JavaScript programs.