Search code examples
javascripthtmlpromptreadonly

Make javascript prompt text read only


I have a prompt containing a url, however I would like to ensure that this text cannot be manipulated (changed, scripts injected, etc.). Would making this text "readonly" solve this problem? I'll post my code below, thank you!

Html
<div id="button">

Js
<script>
    document.getElementById("button").onclick = function () {
        prompt('Copy and share this link!', 'www.webapp.com');
    };
</script>

Solution

  • Not sure if there is a solution for that, as JS prompts are not designed for this use case.

    In case there is no direct solution, maybe you can try a more "traditional" approach, using a copy library, such as Clipboard.js -- which might be a friendlier solution for your users, too.