like alert() but using a dialog with a textarea: with newlines and editable and selectable text.
Likewise for prompt(), a dialog with textarea and callback on close.
<hr>
<textarea id="ta" rows="10">
Some text.
Some more text on a long long long long long long long long long long long line.
Andaverylongunbrokenwoooooooooooooooooooooooooooooooooooooooooooooooooooooooord.
</textarea>
← popup dialog with this string, using:<br>
<button onclick="s=document.querySelector('#ta').value; alert(s);">
alert()
</button>
<button onclick="s=document.querySelector('#ta').value; alertTextField(s);">
alertTextField()
</button>
<button onclick="s=document.querySelector('#ta').value; alertTextField2(s);">
alertTextField2()
</button>
<button onclick="s=document.querySelector('#ta').value; console.log(prompt(s, s));">
prompt()
</button>
<button id="button3">
promptTextField()
</button>
<hr>
Note that you can not select the text in a default <code>alert()</code>.<br>
Also note that newlines are lost in the selectable value input of a <code>prompt()</code>.<br>
Attempt a simple custom dialog with a textarea where you keep the newlines and can select all text, and can also be modified easily to support anything you want.
<hr>
So far this is the most basic easy to use variant:
<pre id="examples"></pre>
<hr>
<details>
<summary>links/references: ...</summary>
<ul>
<li><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog">MDN <dialog></a>
<li><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/Window/alert">MDN alert()</a>
<li><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt">MDN prompt()</a>
</ul>
</details>