How to Use JS to display line breaks in alert _ javascript skills

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.