Jump to content

php and js copy to clipboard


Lodius2000

Recommended Posts

Hi, I know zero js but heres what i got, I wanna copy $id to the clipboard and this isnt working, what am i doing wrong, and is this only for 1 browser, do i need a different method for other browsers?

 

<?php

$id = "6228";

print "<script type=\"text/javascript\">\n";
print "var id;\n";
print "id=$id;\n";
print "id.execCommand(\"Copy\");";
print "</script>";


?>

 

thanks

Link to comment
Share on other sites

Well I dont think you can do that with Javascript alone... many issues... portability, compatibility, security .. try this:

 

 

 

 

function copyToClipboardViaFlash(text) {

var flashId = 'flashId-HKxmj5';

    var clipboardSWF = 'http://appengine.bravo9.com/copy-into-clipboard/clipboard.swf';

 

if (!document.getElementById(flashId)) {

var div = document.createElement('div');

div.id = flashId;

document.body.appendChild(div);

}

 

document.getElementById(flashId).innerHTML = '';

var content = '<embed src="' + clipboardSWF + '" FlashVars="clipboard=' + encodeURIComponent(text) + '" width="0" height="0" type="application/x-shockwave-flash"></embed>';

document.getElementById(flashId).innerHTML = content;

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.