Alert newline prevents copying in Chrome

Viewed 45

I want to display a window.alert and allow the user to copy part of the output. However, if the text contains a newline, Chrome prevents copying. It works as expected in Firefox. Is there a workaround for this in Chrome? I know I can use prompt instead, but I would need a newline in the selected text which doesn't appear to work either. See this fiddle to test this MWE:

<html>
<body>
Alert A: <a onclick="test_copy()"><u>no newline</u></a>
<br>
Alert B: <a onclick="test_copy_b()"><u>newline</u></a>
<br>
Prompt: <a onclick="test_copy_c()"><u>newline</u></a>
<script>
function test_copy() {
 window.alert("Can you copy: //path/to/file1 //path/to/file2");
}
function test_copy_b() {
 window.alert("Can you copy:\n //path/to/file1 \n //path/to/file2");
}
function test_copy_c() {
 window.prompt("Can you copy:", "//path/to/file1 \r\n //path/to/file2");
}
</script>
</body>
</html>
0 Answers
Related