2013-05-03 158 views
1

我知道已經有一個線程與此有關,但我需要更多信息。目前,我有這個代碼,我得到了形成另一個線程,如何在瀏覽器中添加上下文菜單?

public void AttachContextMenu() 
    { 
     try 
     { 
      if (webTab1.IsScriptEnabled) 
      { 
       webTab1.InvokeScript("execScript", "function FindParentLink(item) \r\n{\r\n\tif (!item.parentNode)\r\n\t\treturn null;\r\n\tif (item.tagName.toLowerCase() == 'a') \r\n\t{\r\n\t\treturn item;\r\n\t} \r\n\telse \r\n\t{\r\n\t\treturn FindParentLink(item.parentNode);\r\n\t}\r\n}\r\n\r\nfunction FindParentImage(item) \r\n{\r\n\tif (!item.parentNode)\r\n\t\treturn null;\r\n\tif (item.tagName.toLowerCase() == 'img') \r\n\t{\r\n\t\treturn item;\r\n\t} \r\n\telse \r\n\t{\r\n\t\treturn FindParentImage(item.parentNode);\r\n\t}\r\n}\r\n\r\nfunction HandleContextMenu() \r\n{\r\n\tvar linkItem = FindParentLink(event.srcElement);\r\n var imageItem = FindParentImage(event.srcElement);\r\n var notifyOutput = '';\r\n if (linkItem != null) if (linkItem.href != null) notifyOutput += linkItem.href;\r\n if (imageItem != null) if (imageItem.src != null) notifyOutput += imageItem.src;\r\n if (notifyOutput != '')\r\n  window.external.notify(notifyOutput);\r\n else\r\n\t\twindow.external.notify('NOTLINKIMG');\r\n}"); 
       webTab1.InvokeScript("execScript", "document.oncontextmenu = HandleContextMenu;"); 
      } 
     } 
     catch 
     { 
     } 
    } 

線程說,當瀏覽器已經完成加載,你只需要調用這個方法,雖然它似乎沒有工作。

任何想法,我怎麼能得到它的工作?

回答

0

這僅適用於Windows Phone 7.X。不是8

AddHandler wb.Loaded, Sub(sendr As Object, ev As EventArgs) 
    wb.IsScriptEnabled = True 
    AttachContextMenu() 
End Sub 
AddHandler wb.ScriptNotify, Sub(sender As Object, e As Microsoft.Phone.Controls.NotifyEventArgs) 
    Diagnostics.Debug.WriteLine(e.Value.ToString) 
End Sub 

如果你知道如何打開在WP8 WebBrowser控件一個上下文菜單,請讓我們都知道。 在WP8上,我使用onmousedown事件,定時器和onmouseout事件與WP7的findparentlink函數結合使用。

相關問題