0

Hey just a quick question!

I want to have a text selected in the dialog window so that the user can just press CTRL + C to copy that text. Can it be done and if it can, how?

An example of this is the javascript alert prompt. There the user can u just press CTRL + C to copy a text. Anyway to implement this in the jquery dialog div?

Thanks peeps!

Reft
  • 2,333
  • 5
  • 36
  • 64
  • possible duplicate of [How to create a popup box where users can copy text?](http://stackoverflow.com/questions/18342252/how-to-create-a-popup-box-where-users-can-copy-text) – Rachel Gallen Jun 26 '14 at 18:22

1 Answers1

0

I would use the jQuery UI Dialog widget for this, http://api.jqueryui.com/dialog/. To highlight text you would need to use another plugin as mentioned here, Highlight a word with jQuery.

If you are OK with using a textarea inside your dialog, try this.

<div><button id="opener">open the dialog</button>
<div id="dialog" title="Dialog Title"><textarea id="test">I'm a textarea inside a dialog</textarea></div>
</div>

<script type="text/javascript">
<!--
$(document).ready(function() {
    $( "#dialog" ).dialog({ autoOpen: false });
    $( "#opener" ).click(function() {
        $( "#dialog" ).dialog("open");
        $( "#dialog textarea" ).select();
    });
});
//-->
</script>
Community
  • 1
  • 1