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
https://forums.phpfreaks.com/topic/127938-php-and-js-copy-to-clipboard/
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;

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.