Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a div tag that I want to display 30 secons after copying content on a web page, below is the code.
Content To Be Copied:
<div class="copy">Copy This Conent</div>

Div Tag To DIsplay After 30sec of Copying:
<div id="dsply">The Content Has Been Copied</div>

A good solution to this will be appreciated.

What I have tried:

I have been able to solve the display after 30 secons using js:
$(function(){

    $('#dsply').hide();

    setTimeout(function(){
        $('#dsply').fadeIn('slow');
    },30000);

});


But I actually want this to display 30 secons after copying web page content.
Posted
Updated 3-Feb-20 10:09am
Comments
ZurdoDev 3-Feb-20 8:16am    
After someone presses Ctrl+C or do you have a button that the user will click to copy?
cHl Security 3-Feb-20 10:18am    
AFter someone press ctrl+c or right clicking, select then copy. More so I would appreciate if you and also help me in vice vera on how to make a dive disappear 30 secs after copy event occured. Best Regards.

1 solution

Use the oncopy event of your document. This event is fired when the user copies content by pressing Ctrl-C, by using the context menu and choosing Copy, or when using the browser window menu and choosing edit/copy.

So all you need do is call your function in response to that event:
JavaScript
document.oncopy =$(function(){

    $('#dsply').hide();

    setTimeout(function(){
        $('#dsply').fadeIn('slow');
    },30000);

});
Read more about clipboard events, including cancelling them, accessing clipboard data etc at https://www.w3.org/TR/clipboard-apis/#clipboard-event-copy[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900