//运行代码
function runEx(cod1) {
cod = document.getElementById(cod1)
var code = cod.value;
if (code != "") {
var newwin = window.open('', '', '');
newwin.opener = null
newwin.document.write(code);
newwin.document.close();
}
}
//复制代码
function doCopy(ID) {
if (document.all) {
textRange = document.getElementById(ID).createTextRange();
textRange.execCommand("Copy");
}
else {
//alert("此功能只能在IE上有效");
copyToClipboard(document.getElementById(ID).value);
}
}
//另存为代码
function saveCode(cod1) {
cod = document.getElementById(cod1)
var code = cod.value;
if (code != "") {
var winname = window.open('', '_blank', 'top=10000');
winname.document.open('text/html', 'replace');
winname.document.write(code);
winname.document.execCommand('saveas', '', 'code.htm');
winname.close();
}
}
function copyToClipboard(txt) {
if (window.clipboardData) {
window.clipboardData.clearData();
window.clipboardData.setData("Text", txt);
} else if (navigator.userAgent.indexOf("Opera") != -1) {
window.location = txt;
} else if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
alert("被浏览器拒绝!\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
}
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 false;
clip.setData(trans, null, clipid.kGlobalClipboard);
}
}

JS 运行、复制、另存为 代码。的更多相关文章

  1. JS实现复制网页内容自动加入版权内容代码和原文链接

    JS实现复制网页内容自动加入版权内容代码和原文链接 实现代码:在body内放入如下代码即可: <script type="text/javascript"> var S ...

  2. Cocos Creator JS web平台复制粘贴代码(亲测可用)

    Cocos Creator JS web平台复制粘贴代码(亲测可用) 1 webCopyString: function(str){ var input = str; const el = docum ...

  3. Js复制链接代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. NET代码运行在服务器JS运行在客户端

    using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Web;usi ...

  5. 浅析 Node.js 的 vm 模块以及运行不信任代码

    在一些系统中,我们希望给用户提供插入自定义逻辑的能力,除了 RPC 和 REST 之外,运行客户提供的代码也是比较常用的方法,好处是可以极大地减少在网络上的耗时.JavaScript 是一种非常流行而 ...

  6. JS对象复制

    在JavaScript很多人复制一个对象的时候都是直接用"=",因为大家都觉得脚本语言是没有指针.引用.地址之类的,所以直接用"="就可以把一个对象复制给另外一 ...

  7. js 实现复制剪切

    原生js实现复制 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...

  8. 如何通过setTimeout理解JS运行机制详解

    setTimeout()函数:用来指定某个函数或某段代码在多少毫秒之后执行.它返回一个整数,表示定时器timer的编号,可以用来取消该定时器. 例子 ? 1 2 3 4 5 console.log(1 ...

  9. 【转】js实现复制到剪贴板功能,兼容所有浏览器

    两天前听了一个H5的分享,会议上有一句话,非常有感触:不是你不能,而是你对自己的要求太低.很简单的一句话,相信很多事情不是大家做不到,真的是对自己的要求太低,如果对自己要求多一点,那么你取得的进步可能 ...

随机推荐

  1. Maven Web应用

    创建Web应用程序 要创建一个简单的java web应用程序,我们将使用Maven的原型 - web应用插件.因此,让我们打开命令控制台,进入到C: MVN目录并执行以下命令mvn命令. C:MVN& ...

  2. jpa无外键配置

    在用jpa这种orm框架时,有时我们实体对象存在关联关系,但实际的业务场景可能不需要用jpa来控制数据库创建数据表之间的关联约束,这时我们就需要消除掉数据库表与表之间的外键关联.但jpa在处理建立外键 ...

  3. repo sync出现“fatal: '../platform/abi/cpp.git' does not appear to be a git repository”的解决方案

    在我下载Android源代码时,在最后一步调用repo sync,出现“fatal: '../platform/abi/cpp.git' does not appear to be a git rep ...

  4. 【经验之谈】Git使用之TortoiseGit配置VS详解;国内几大Git代码托管网站

    转载自: http://www.cnblogs.com/xishuai/p/3590705.html   http://www.cnblogs.com/shanyou/p/3662482.html

  5. k8s sidecar, Ambassador, Adapter containers

    When you start thinking in terms of Pods, there are naturally some general patterns of modular appli ...

  6. ORACLE 几个我忍了他很多年的问题

    ① DataGuard环境,主库创建的临时文件,不在备库上创建 ② 创建11G R2 Rac环境时,在RHEL 6.0及以后版本上,最后执行root.sh命令时,以及重新启动OS后启动ohasd,都需 ...

  7. vue 中view层中方法的使用

    1.使用filters computed:{ }, filters: { filterA: function(value) { return value + 'wh' } }, 2.用法:  {{it ...

  8. ubuntu 12.04和Windows 7双系统的安装方法

    ubuntu是一个操作系统,和安卓一样同是linux内核下的子民,所以来这贡献一下,也求JW放出安卓4.0原生正式版,我只想要这个. 前几天发布了ubuntu12.04LTS 版本,兴奋ing. 看到 ...

  9. hive kettle 学习笔记

    学习网址 http://wiki.pentaho.com/display/BAD/Transforming+Data+within+Hive

  10. 内存管理 初始化(四)mem_init bootmem 迁移至伙伴系统

    mm_init中执行mem_init,将原通过bootmem分配器管理的低端内存 及  通过meminfo得知的高端内存释放到伙伴系统中,最后bootmem位图本身占用的低端内存物理页也被释放进伙伴系 ...