Upon clicking the "Open Windows" button in Code A, I expected the two links to open in two tabs simultaneously in Chrome, which is exactly what happened.
However, when I added a blank line in the textarea control in Code B, only the link http://www.google.com/ was able to be opened. Why is this happening?
I suspect that the condition if (url.length != 0) {...} might be causing the issue, but I'm not certain.
Code A
<html>
<head>
<script src="Js/jquery-3.6.3.min.js"></script>
<script type="text/javascript">
function open_win() {
let links = $('#textID').val();
if (links) {
let row = links.split('\n');
row.forEach((original_url) => {
var url = original_url.match(/\b(http|https)?:\/\/\S+/gi)[0];
if (url.length != 0) {
window.open(url);
}
});
}
}
</script>
</head>
<body>
<textarea id="textID" name="message" rows="10" cols="80">
AAA http://www.google.com/
http://www.msn.com/ BBB
</textarea>
<br />
<input type=button value="Open Windows" onclick="open_win()">
</body>
</html>
Code B
//Same
<textarea id="textID" name="message" rows="10" cols="80">
AAA http://www.google.com/
http://www.msn.com/ BBB
</textarea>
//Same