<Html xmlns = "http://www.w3.org/1999/xhtml"> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/> <Title> JavaScript copy code, compatible with multiple browsers </title> </Head> <Script language = "javascript"> CopyValue = function (strValue ){ If (isIE ()){ ClipboardData. setData ("Text", strValue ); Alert ("You have copied this address "); } Else { Copy (strValue ); Alert ("the content has been copied! "); } } Function isIE (number ){ If (typeof (number )! = Number ){ Return !! Document. all; } } Function copy (text2copy ){ Var flashcopier = 'flashcopier '; If (! Document. getElementById (flashcopier )){ Var divholder = document. createElement ('div '); Divholder. id = flashcopier; Document. body. appendChild (divholder ); } Document. getElementById (flashcopier). innerHTML = ''; Var divinfo = '<embed src = "http://files.jb51.net/demoimg/200910/_clipboard.swf" FlashVars = "clipboard =' + text2copy + '" width = "0" height = "0" type = "application/x-shockwave -flash "> </embed> '; // here is the key Document. getElementById (flashcopier). innerHTML = divinfo; } </Script> <Div class = "phoinfo"> Texture address: <input name = "txtPhotoPath" value = "www.daimajiayuan.com" id = "txtPhotoPath" type = "text" size = "65"/> <Input type = "button" name = "btnCopy" id = "btnCopy" onClick = "copyValue ('www .daimajiayuan.com ');" value = "copy"/> </Div> </Body> </Html> |