当前位置: 首页 > 图文教程 > 数据库 > MSSQL > [js]javascript与剪贴板交互

MSSQL
SQLSERVER 中datetime 和 smalldatetime类型分析说明
数据库清除日志文件(LDF文件过大)
按日期选择最晚日期与最早日期对应的数的差值
sql 时间函数 整理的比较全了
SQL Server全文检索查询浅析
SQL 存储过程基础语法之一
SQL Substring提取部分字符串
用户"sa"登陆失败 SQLServer 错误18456的解决方法
MSSQL 检查所使用的语句是否符合标准
drop,truncate与delete的区别
SQL语句查询数据库中重复记录的个数
SQL 导入导出Excel数据的语句
可以获取客户端的IP地址的sql语句
SQL 根据汉字获取全拼的代码
sqlserver exists,not exists的用法
sqlserver substring函数使用方法小结
sql 判断数据库,表,存储过程等是否存在的代码
做购物车系统时利用到得几个sqlserver 存储过程
Sql2000数据库的备份文件恢复到Sql2005的方法
sql 分组查询问题

MSSQL 中的 [js]javascript与剪贴板交互


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 47 ::
收藏到网摘: n/a

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剪贴板里的字符串吗?
比如在网页中实现点击一个文本框 就把剪贴板里的字符粘贴进去
当然可以
<form>
<p>
<input name=txtSearch value="">
<input type=button value=Copy2Clip onclick='javascript: var textRange=txtSearch.createTextRange(); textRange.execCommand("Copy")'>
</p>
<p>
<input name="copyto" type="text" id="copyto">
<input type=button value=PastefromClip onclick='javascript: var textRange=copyto.createTextRange(); textRange.execCommand("Paste")'>
</p>
</form>
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 <= 0 then
{ 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