IE, Firefox can support JavaScript to write content to the Clipboard
IE can easily support clipboard content writing commands, can use ExecCommand (), can also use the window.clipboarddata.
With execcommand, you need to select from the page what you want to copy to the Clipboard, such as the following code:
Copy Code code as follows:
var doc = Obj.createtextrange ();
Doc.select ();
Doc.execcommand (' copy ');
Using the Window.clipboarddata method, the code also implements Firefox's ability to write to the Clipboard:
Copy Code code as follows:
if (window.clipboarddata)//ie
{
Window.clipboardData.clearData ();
Window.clipboardData.setData ("Text", txt);
}
else if (window.netscape)
{
try {netscape.security.PrivilegeManager.enablePrivilege ("Universalxpconnect");
}
catch (E)
{
Alert ("Please visit ' about:config ' and set Signed.applets.codebase_principal_support as ' true ');
Prompts users for security settings for open browsers
}
var clip = components.classes["@mozilla. Org/widget/clipboard;1"].createinstance ( Components.interfaces.nsIClipboard);
if (!clip)
Return
var trans = components.classes["@mozilla. Org/widget/transferable;1"].createinstance ( Components.interfaces.nsITransferable);
if (!trans)
Return
Trans.adddataflavor (' Text/unicode ');
var str = new Object ();
var len = new Object ();
var str = components.classes["@mozilla. Org/supports-string;1"].createinstance ( Components.interfaces.nsISupportsString);
var copytext = txt;
Str.data = CopyText;
Trans.settransferdata ("Text/unicode", str,copytext.length*2);
var clipid = Components.interfaces.nsIClipboard;
if (!clip)
Return
Clip.setdata (Trans,null,clipid.kglobalclipboard);
}
The above code can be implemented in IE, Firefox to the Clipboard to write custom content, but opera and WebKit kernel browser More security requirements, do not support this JavaScript directly manipulate the contents of the Clipboard, only through other scripting language "curve Save the Nation."
Opera, Safari, Chrome, using ActionScript to write content to the Clipboard
The implementation of the original action button with flex or Flash to achieve its appearance, replace the original picture or Text button, and then click the button, execute the following ActionScript script:
Get what you need to write to the Clipboard from the browser environment
var s:string = String (Externalinterface.call ("Geturl4clipboard")); Geturl4clipboard is the JavaScript method for the return clipboard content on the page
Set Clipboard contents
System.setclipboard (s);
Invoke JavaScript functions that need to continue after the contents of the Clipboard have been set, such as prompting user information
Externalinterface.call ("copyurlcompleted"); Copyurlcompleted is the JavaScript method on the page and continues to perform the work after replication