Javascript Browser Window confirm() Method with line-breaks

Introduction

Confirmation box with line-breaks:

confirm("Press a button!\nEither OK or Cancel.");

Click the button to demonstrate line-breaks in a confirm box.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from w ww . j av a2 s .  co m*/
  var txt;
  var r = confirm("Press a button!\nEither OK or Cancel.\nThe button you pressed will be displayed in the result window.");
  if (r == true) {
    txt = "You pressed OK!";
  } else {
    txt = "You pressed Cancel!";
  }
  document.getElementById("demo").innerHTML = txt;
}
</script>

</body>
</html>



PreviousNext

Related