Java script direct copy to clip board

Discussion in 'JavaScript' started by ironmankho, Sep 30, 2009.

  1. #1
    i have little script like

    echo '<script type="text/javascript">var url="'.$url.$name.'"; alert(url)</script>';
    PHP:
    now i want this variable direct copy to window clipboard with out click any button .because i already searched many tutorial that come with click ....but i want simple variable to window clipboard.

    simple solution :


    http://lab.artlung.com/copy-to-clipboard-javascript/

    <script language="javascript" type="text/javascript">

    // Microsoft Internet Explorer only
    // Manipulating the system clipboard in JavaScript
    // Read more at:
    // http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/clipboarddata.asp

    // set the clipboard
    var x = 'Whatever you want on the clipboard';
    window.clipboardData.setData('Text',x);

    // get the clipboard data
    window.clipboardData.getData('Text');

    // clear the clipboard
    // window.clipboardData.clearData();

    </script>

    Thanks for reading this ..problem solved
     
    Last edited: Sep 30, 2009
    ironmankho, Sep 30, 2009 IP
  2. Jj delc

    Jj delc Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    beware that this will only work on Microsoft browsers (Internet explorer) and not in other browsers (firefox, safari, chrome) or any other OS (iphone, mac, linux).

    For security reasons webpages are not allowed to see or alter what's on a user's clipboard. Imagine that I made a website that obtained the text on your clipboard and sent it to my webserver. Or that you've copied some important data on your clipboard and a webpage erases it.
     
    Jj delc, Oct 6, 2009 IP
  3. lawracri

    lawracri Peon

    Messages:
    74
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
  4. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #4
    dimitar christoff, Oct 7, 2009 IP