FireFox浏览器复制到剪贴板功能的javascript源代码
根据浏览器复制到剪贴板的功能,具体代码如下:
var txt="要复制到剪贴板的内容";
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("你使用的FF浏览器,复制功能被浏览器拒绝!\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');
&nb
相关文档:
JavaScript 中使用 replace 达到 replaceAll的效果
方法: string.replace(new RegExp(oldString,"gm"),newString))
gm g=global, m=multiLine , 大致上方法就是这样的,可以实现替换全部指定字串
另一个简单的验证JS的方法:
在浏览器地址栏输入
javascript:alert("abcabc ......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JavaScript真正的鼠标放上动画加载大图的代码</title>
<style>
*{ padding:0; margin ......
<script language="JavaScript" type="text/javascript" >
<!--
.
//-->
</script>
.language已经被弃用,但为了兼容旧版本浏览器而保留,所以建议同时使用这language和type两个
.<!--- //-->& ......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>DOM</title>
<meta http-equiv="Content-Type&quo ......
一、正则表达式通过RegExp类实现,RegExp对象的构造函数可以带一个或两个参数。第一个参数(或只有一个参数)是描述需要进行匹配的模式字符串,如果还有第二个参数,这个参数则指定了额外的处理指令。
定义正则表达式:
1、只匹配字符串中出现的第一个单词"cat";区分大小写
var reCat = new RegExp("cat&q ......