Showing posts with label Copy. Show all posts
Showing posts with label Copy. Show all posts

Saturday, October 11, 2008

Javascript event handler for text cut/paste/copy

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>some javascript element event example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>

<body>
<h3>Element.onpaste</h3>
<textarea id="editor" rows="3" cols="80" onpaste="pasteIntercept(event);">
Try pasting text into this area!
</textarea>

<h3>Log</h3>
<textarea rows="5" cols="80" id="log" readonly="true"></textarea>

<h3>Element.oncontextmenu</h3>
<div oncontextmenu="return false;" style="border: #ddd 1px solid; width: 642px; color: #369;">
prevent element context menu<br>
阻止此元素上的右键菜单弹出
</div>

<h3>Element.oncut and Element.copy</h3>
<input type="text" size="80" name="preventpaste" value="text can't be cut or copy!" oncut="return false" oncopy="return false"/>

<script type="text/javascript">
function log(txt)
{
document.getElementById("log").appendChild(document.createTextNode(txt + "\n"));
}

function pasteIntercept(event)
{
log("Pasting!");
event.preventDefault(); // event.returnValue = false; // IE
return false;
}
</script>

</body>
</html>

以上的几个方法在IE/Safari/Firefox3里都有对应的实现,在firefox3中测试通过,firefox2和opera未测试,应该还没有支持这些事件处理器。
Reference:
http://developer.mozilla.org/en/DOM/element.onpaste

Monday, February 04, 2008

Using javascript copy text string to user's clipboard

1、System.setClipboard() 方法允许 SWF 文件用纯文本字符串替换剪贴板内容。这不会带来任何安全性风险。为避免因剪切或复制到剪贴板的密码和其它敏感数据所带来的风险,FLASH AS3并未提供相应的“getClipboard”(读取)方法。


if (clipboard.length)
{
System.setClipboard(clipboard);
}

2、JavaScript调用FLSAH里设置的回调方法,将文本内容clipboard传给FLASH,由FLASH完成copy到剪贴板的动作。
另在IE7里操作剪贴板会有提示框警告。

Wednesday, April 18, 2007

Ruby中的变量,引用和对象

#Ruby变量保持对对象的引用并且 = 操作符拷贝引用.同时,例如a += b的自赋值实际上被翻译为a = a + b. 因此意识到在某个操作中你事实上是创建了新的对象还是修改了一个现存的对象是明智的.
#例如, string << "another" 比 string += "another" 更安全(不创建额外对象), 所以如果它存在的话你使用任何类定义的(class-defined)更新方法(update-method) 应该更好(如果那是真是你的意图). 然而,也要注意关连同一个对象的所有其他变量上的"副作用":

a = 'aString'
c = a
a += ' modified using +='
# 相当于 a = a + ' modified using +=', 重新赋值给新变量a, 这不会改变前面的c值(引用原先a值)
puts c # -> "aString"

a = 'aString'
c = a
a << ' modified using <<'
puts c # -> "aString modified using <<"
# 这个直接就改变了a本身的值,没有新建对象(string << "another" 比 string += "another" 更安全(不创建额外对象)),而c只是a的引用,所以c的值也变化了。