Open a new window when someone tries to copy text?

Discussion in 'Programming' started by InternetG33k, Jan 4, 2009.

  1. #1
    Is it possible to open a new window to the file of my choice when someone tries to copy text on my website?

    So basically I want a textarea box with some text in it but when someone copies the text inside a new window will open up. I also want to limit it so that it only does this on first copy.

    If you help i will give you a paypal donation
     
    InternetG33k, Jan 4, 2009 IP
  2. shaileshk

    shaileshk Well-Known Member

    Messages:
    455
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    In a WinForms app override the ProcessCmdKey:
    
    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
    switch (msg.Msg)
    {
    case 0x100:
    case 0x104:
    switch (keyData)
    {
    case Keys.Control | Keys.C:
    MessageBox.Show("Ctrl + C pressed");
    break;
    }
    break;
    }
    return base.ProcessCmdKey(ref msg, keyData);
    }
    
    Code (markup):
     
    shaileshk, Jan 4, 2009 IP
  3. manjifera

    manjifera Well-Known Member

    Messages:
    232
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    118
    #3
    Hi there
    chk out this i hope thius will help you.

    http://hindimp3songs.info/test.htm
    if you want to chk it againg delete your cookies. as this works on cookies to open window at one time.

    will appreciate you if you donate me via paypal.

    Thanks!
     
    manjifera, Jan 4, 2009 IP
  4. shaileshk

    shaileshk Well-Known Member

    Messages:
    455
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #4
    whenever a 'KeyDown' event will do the trick, however, since a Ctrl-C involves 2 keys it is not passed to the KeyDown event handler as a 'Single' keystroke, but it is passed as a single keystroke to 'KeyPress'.

    
    
    ------------start VB.NET code-----------------------------
    Select Case e.KeyChar
                    Case  Convert.ToChar(3) 'Ctrl-C Copy
                        'Do something when Ctrl-C encountered
                    Case  Convert.ToChar(22) 'Ctrl-V Paste
                        'Do something when Ctrl-C encountered
                    Case  Convert.ToChar(24) 'Ctrl-X Cut
                        'Do something when Ctrl-C encountered
    End Select
    ------------end VB.NET Code-----------------------------
    
    Code (markup):
     
    shaileshk, Jan 4, 2009 IP
  5. shaileshk

    shaileshk Well-Known Member

    Messages:
    455
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #5
    In JavaScript

    
    function keypress(ev) {
    if (!ev) var ev=window.event;
    
    if (ev.ctrlKey) {
    return;
    }
    
    var kc;
    if (ev.keyCode) kc=ev.keyCode;
    if (ev.which) kc=ev.which;
    //if (kc==13) kc=10;
    var k=String.fromCharCode(kc);
    process_key(k);
    
    ev.cancelBubble=true;
    if (ev.stopPropagation) ev.stopPropagation();
    return false;
    }
    
    
    function keydown(ev) {
    if (!ev) var ev=window.event;
    
    if (!ev.ctrlKey || ev.keyCode==17) {
    return;
    }
    
    var kc=ev.keyCode;
    process_key(String.fromCharCode(kc-64));
    
    ev.cancelBubble=true;
    if (ev.stopPropagation) ev.stopPropagation();
    return false;
    }
    
    
    document.onkeypress=keypress;
    document.onkeydown=keydown;
    
    Code (markup):
     
    shaileshk, Jan 4, 2009 IP
  6. shaileshk

    shaileshk Well-Known Member

    Messages:
    455
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #6
    I have checked it' worked.

    You have used the cookies . Right !!!

    Great idea.
     
    shaileshk, Jan 5, 2009 IP
  7. seo_specialist

    seo_specialist Guest

    Messages:
    106
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    yes as many friends mentioned here its possible on click event and other function also but a nice idea....
     
    seo_specialist, Jan 5, 2009 IP
  8. InternetG33k

    InternetG33k Banned

    Messages:
    493
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You "win" send me your paypal details
     
    InternetG33k, Jan 5, 2009 IP