您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

[js]javascript与剪贴板交互

2024/5/30 19:39:29发布13次查看
[js]javascript与剪贴板交互
1.怎样操作剪贴板,从而实现复制、剪切与粘贴?同时判断剪贴板里边的数据是否是文本?
if (!isclipboardformatavailable(cf_text))
return;
if (!openclipboard(hwndmain))
return;
hglb = getclipboarddata(cf_text);
if (hglb != null)
{
lptstr = globallock(hglb);
if (lptstr != null)
{
// call the application-defined replaceselection
// function to insert the text and repaint the
// window.
replaceselection(hwndselected, pbox, lptstr);
globalunlock(hglb);
}
}
closeclipboard();
2.可以使用javascript获得windows剪贴板里的字符串吗?
比如在网页中实现点击一个文本框 就把剪贴板里的字符粘贴进去
当然可以
3.javascript和剪贴板的交互
一般可以这样将id为‘objid'的对象的内容copy到剪贴板
var rng = document.body.createtextrange();
rng.movetoelementtext(document.getelementbyid(objid));
rng.scrollintoview();
rng.select();
rng.execcommand(copy);
rng.collapse(false);
settimeout(window.status='',1800)
也可以用rng.execcommand(past);将剪贴板的内容粘到光标当前位置。
内容参见msdn 的textrange对象。
不过,copy到剪贴板的都是不带html标签的,所有html标签都将被过滤。
4.window.clipboarddata.getdata(text) //可以获得剪贴版的文字
window.clipboarddata.setdata(text,你的内容) //向剪贴板里写文本信息
5.怎么判断剪贴板中的数据是否为字符串而不是图片或别的信息?
private sub command1_click()
if clipboard.getformat(vbcftext) or clipboard.getformat(vbcfrtf) then
msgbox ok
end if
end sub
6.请问如何判断剪贴板中不为空?
一、
eg
判断windows剪贴板里是否为空,没有则读取图片到image中
uses clipbrd;
if clipboard.hasformat(cf_picture) then
image1.picture.assign(clipboard);
二、
uses clipbrd;
procedure tform1.button1click(sender: tobject);
begin
if clipboard.formatcount { todo : 空 };
end;
7.怎样确定剪贴板中的数据是否为图象?
getformat 方法示例
本示例使用 getformat 方法确定 clipboard 对象上数据的格式。要检验此示例,可将本例代码粘贴到一个窗体的声明部分,然后按 f5 键并单击该窗体。
private sub form_click ()
' 定义位图各种格式。
dim clpfmt, msg ' 声明变量。
on error resume next ' 设置错误处理。
if clipboard.getformat(vbcftext) then clpfmt = clpfmt + 1
if clipboard.getformat(vbcfbitmap) then clpfmt = clpfmt + 2
if clipboard.getformat(vbcfdib) then clpfmt = clpfmt + 4
if clipboard.getformat(vbcfrtf) then clpfmt = clpfmt + 8
select case clpfmt
case 1
msg = the clipboard contains only text.
case 2, 4, 6
msg = the clipboard contains only a bitmap.
case 3, 5, 7
msg = the clipboard contains text and a bitmap.
case 8, 9
msg = the clipboard contains only rich text.
case else
msg = there is nothing on the clipboard.
end select
msgbox msg ' 显示信息。
end sub
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product