function CopyToClipboard(s) { var success = true; if (window.clipboardData) { // Internet Explorer window.clipboardData.setData("Text", s); } else { var forExecElement = CreateElementForExecCommand(s); SelectContent(forExecElement); var supported = true; try { if (window.netscape && netscape.security) { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } success = document.execCommand("copy", false, null); } catch (e) { success = false; } document.body.removeChild(forExecElement); } if (success) { $.alert("链接已复制!"); } else { $.alert("链接复制失败!"); }}function CreateElementForExecCommand (textToClipboard) { var forExecElement = document.createElement ("div"); // place outside the visible area forExecElement.style.position = "absolute"; forExecElement.style.left = "-10000px"; forExecElement.style.top = "-10000px"; // write the necessary text into the element and append to the document forExecElement.textContent = textToClipboard; document.body.appendChild (forExecElement); // the contentEditable mode is necessary for the execCommand method in Firefox forExecElement.contentEditable = true; return forExecElement;}function SelectContent (element) { // first create a range var rangeToSelect = document.createRange (); rangeToSelect.selectNodeContents (element); // select the contents var selection = window.getSelection (); selection.removeAllRanges (); selection.addRange (rangeToSelect);}