On copy event, i need to display confirm dialog (we use fancybox dialogs in all project) and depending on user choice add some text (reference) to the copied text or leave the text as it is.
And the problem is that - when dialog appears copy function continues to go further and don't wait till confirmation.
Is there a way to pause the event and then continue? I know i can stop event e.preventDefault();. Maybe there is some way to manualy invoke copy event and pass modified text as selection?

$("body").bind ('beforecopy', function (e) { 
    if (typeof window.getSelection == "undefined") return; 
    var body_element = document.getElementsByTagName('body')[0];
    selection = window.getSelection();
    if (("" + selection).length < 50) return;
        if (ret==true) { 
            restOfTheCode(body_element); //function that adds the text

FancyBox confirmation dialog.

function fancyConfirm(callback) {
    var ret = false;
    var content =
        '<div class="popup_form">'+
        '<div class="naismessage"><p>Copy with reference?</p><br>'+
        ' <input type="button" class="button small left" id="fancyConfirm_ok" value="Yes">'+
        ' <input type="button" class="button small" id="fancyConfirm_cancel" value="No">'+
            openSpeed   : 'fast',
            closeSpeed  : 'fast',
            minWidth: '50',
            minHeight: '50',
            title: null,
            beforeShow: function () {
                $("#fancyConfirm_cancel").click(function() {
                    ret = false;
                $("#fancyConfirm_ok").click(function() {
                    ret = true;
            afterClose : function() {
                if (typeof callback == 'function'){
                    callback.call(this, ret);

For adding refernce i use: Click Here

You'll need a true Modal Dialog for that; which is either a builtin browser Confirm Dialog, or the customizable showModalDialog() command.

jQuery uses fake Dialogs;
Which are in fact no dialogs at all, or if we cut some slack, they are at best, no more than Modeless imitations of app Dialogs.

Unable to halt the script execution and wait for confirmatin value.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.