如何用javascript拷贝当前页中被选中的文字?
请教代码如何写,谢谢!
请教代码如何写,谢谢!
document.execCommand("copy") 其他的代码只是辅助演示! [html] <script defer> var oMessage=document.all("phx") var oTextRange=document.body.createTextRange(); with(oTextRange){ moveToElementText(oMessage); execCommand("selectall")} </script> <div id=phx>bluediea</div> <button onclick=document.execCommand("copy")>copy</button> <textarea cols=12 rows=6/>[/html] |
好用:) Thank u! |
帮忙处理一下select,paste. [html] <textarea cols=24 rows=6>study by blueidea HOT.</textarea> <button onclick=document.execCommand("selectall")>select</button> <button onclick=document.execCommand("copy")>copy</button> <button onclick=document.execCommand("paste")>paste</button> <button onclick=document.execCommand("cut")>cut</button> [/html] |
获取焦点就好了! [html] <textarea id=ta cols=24 rows=6>study by blueidea HOT.</textarea> <button onclick=ta.focus();document.execCommand("selectall")>select</button> <button onclick=document.execCommand("copy")>copy</button> <button onclick=ta.focus();document.execCommand("paste")>paste</button> <button onclick=document.execCommand("cut")>cut</button> [/html] |
8错8错 全了 [html] <object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"> <param name="Command" value="Minimize"></object> <object id=hh2 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"> <param name="Command" value="Maximize"></object> <OBJECT id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"> <PARAM NAME="Command" value="Close"></OBJECT> <input type=button value=最小化 onclick=hh1.Click()> <input type=button value=最大化 onclick=hh2.Click()> <input type=button value=关闭1 onclick=hh3.Click()> <input type=button value=关闭2 onClick=javascript:window.close();return false;> <a href="javascript:close();">关闭本窗口</a> <a href=javascript:window.opener=null;window.close()>Close</a> <hr> <textarea id=ta cols=24 rows=6>study by blueidea HOT.</textarea> <button onclick=ta.focus();document.execCommand("selectall")>select</button> <button onclick=document.execCommand("copy")>copy</button> <button onclick=document.execCommand("cut")>cut</button> <button onclick=ta.focus();document.execCommand("paste")>paste</button> <button onclick=document.execCommand("open")>open</button> <button onclick=document.execCommand("saveas")>saveas</button> <hr> <input type=button value=刷新 name=refresh onclick="window.location.reload()"> <input type="button" name="Button" value="导入收藏夹" onClick=window.external.ImportExportFavorites(true,'');> <input type="button" name="Button3" value="导出收藏夹" onClick=window.external.ImportExportFavorites(false,'');> <INPUT name=Button2 onclick="window.external.AddFavorite(location.href, document.title)" type=button value=加入收藏夹> <INPUT name=Submit2 onclick="window.external.ShowBrowserUI('OrganizeFavorites', null)" type=button value=整理收藏夹> <INPUT name=Button onclick='window.location = "view-source:" + window.location.href' type=button value=查看源文件> <INPUT name=Button onclick="window.external.ShowBrowserUI('LanguageDialog', null)" type=button value=语言设置> <INPUT name=Submit onclick=history.go(1) type=submit value=前进> <INPUT name=Submit2 onclick=history.go(-1) type=submit value=后退> [/html] |