积极答复者
IE9无法从被拖放(drag&drop)的链接中取出URL和链接名

问题
-
我想从被拖放(drag&drop)的链接中正确取出URL和链接名(如下面的VB代码例),在windows xp + IE6(7,8)以及windows server 2008 + IE8的环境下是没有问题的,而在windows server 2008 + IE9和windows7 + IE9的环境下有一部分链接可以,一部分不可以(包含javascript的),迄今没找的原因!请求各位大侠予以指点。。。。
*注:因为在发帖时,总是出现<在我们能够验证您的帐户前,正文文本不能包含图片和链接>错误,所以将下面的期待结果中的[http:]用全角英文表示了,实际应为半角英文,特此说明
【测试】
- 测试1:<a href="http://answers.microsoft.com">microsoft home page</a>
期待结果:microsoft home page - http://answers.microsoft.com
实际结果:
- windows xp + IE6(7,8)--------------------OK
- windows server 2008 + IE8---------------OK
- windows server 2008 + IE9---------------OK
- windows7 + IE9---------------------------OK
- 测试2:<a href="javascript:dotest('http://answers.microsoft.com')">microsoft home page</a>
期待结果:microsoft home page - javascript:dotest('http://answers.microsoft.com')
实际结果:
- windows xp + IE6(7,8)--------------------OK
- windows server 2008 + IE8---------------OK
- windows server 2008 + IE9---------------NG
- windows7 + IE9---------------------------NG(链接名microsoft home page 取不到)
【VB代码例】:
' Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As EventArgs) Handles MyBase.Load ' TextBox1.AllowDrop = True 'DragEnter事件的追加 AddHandler TextBox1.DragEnter, AddressOf TextBox1_DragEnter 'DragDrop事件的追加 AddHandler TextBox1.DragDrop, AddressOf TextBox1_DragDrop End Sub Private Sub TextBox1_DragEnter( _ ByVal sender As Object, ByVal e As DragEventArgs) '只接受URL If e.Data.GetDataPresent("UniformResourceLocator") Then e.Effect = DragDropEffects.Link Else e.Effect = DragDropEffects.None End If End Sub Private Sub TextBox1_DragDrop( _ ByVal sender As Object, ByVal e As DragEventArgs) 'drop的URL的取得 Dim url As String = e.Data.GetData(DataFormats.Text).ToString() '链接名 Dim txt As String = Nothing If url.IndexOf("\"c) > -1 Then '一部分浏览器URL和链接名被一起取得 Dim ss As String() = url.Split("\"c) url = ss(0) txt = ss(1) Else 'FILEGROUPDESCRIPTOR结构体的MemoryStream的取得 Dim ms As MemoryStream = _ CType(e.Data.GetData("FileGroupDescriptor"), MemoryStream) 'cFileName的长的取得 ms.Seek(76, SeekOrigin.Begin) Dim len As Integer = 0 While ms.ReadByte() > 0 len += 1 End While 'cFileName部分的byte数组的取得 Dim bs(len - 1) As Byte ms.Seek(76, SeekOrigin.Begin) ms.Read(bs, 0, len) ms.Close() 'Shift JIS txt = System.Text.Encoding.GetEncoding("Shift_JIS").GetString(bs) '.url的确认 If txt.ToLower().EndsWith(".url") Then txt = txt.Substring(0, txt.Length - 4) End If End If '结果的表示 TextBox1.Text = txt + " - " + url End Sub
- 已编辑 drag_Drop 2013年3月27日 14:03 格式调整
答案
-
你好,
>><a href="javascript:dotest('http://answers.microsoft.com')">microsoft home page</a>
href="linkstr" 中linkstr在ie9,ie10中不能通过js function解析后得到,linkstr是什么网页拖拽就打开什么内容,但因为未解析的function不是合法url地址(javascript:dotest('http://answers.microsoft.com')),所以ie屏蔽打开页面。我建议您按下面写法实现在js function中更改url,但它也不能使用拖拽打开页面。
<a href="#" onclick="javascript:location.href=dotest('http://answers.microsoft.com')">microsoft home page</a>Regards,
Chen Yu
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Molly Chen_Moderator 2013年4月3日 2:23
全部回复
-
你好,
可以提供我们你的JS 代码吗?这样我们在ie9上重现下你的问题。 谢谢。
Regards,
Chen Yu
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
你好,
>><a href="javascript:dotest('http://answers.microsoft.com')">microsoft home page</a>
href="linkstr" 中linkstr在ie9,ie10中不能通过js function解析后得到,linkstr是什么网页拖拽就打开什么内容,但因为未解析的function不是合法url地址(javascript:dotest('http://answers.microsoft.com')),所以ie屏蔽打开页面。我建议您按下面写法实现在js function中更改url,但它也不能使用拖拽打开页面。
<a href="#" onclick="javascript:location.href=dotest('http://answers.microsoft.com')">microsoft home page</a>Regards,
Chen Yu
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Molly Chen_Moderator 2013年4月3日 2:23
-
你好,
我所说的是我测试的结果,你可以自己测试一下。
Regards,
Chen Yu
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.