2010-10-05 50 views
1

對Windows窗體使用.NET的Webbrowser控件,訪問DOM非常容易。考慮這種情況從Mono WebBrowser控件訪問HTML DOM?

this.webBrowser1.Navigate 
      (Path.Combine(Application.StartupPath,"TestPage.html")); 

現在,假設你已經測試JavaScript方法在你的HTML頁面,它接受一個字符串PARAM。所以,一旦加載完成,你可能會

webBrowser1.Document.InvokeScript("test", new object[] { "hi" }); 

現在,我試圖在單聲道中運行此。在運行時,Mono應該使用Mono的網絡瀏覽器控制 - http://www.mono-project.com/WebBrowser。我發現一些非常奇怪的行爲(請參閱更新)

問題是,如何通過Mono的webbrowser控件訪問HTML DOM,可能調用腳本?

更新

就指出,webBrowser1.Document爲空,只有當我連接到網絡。否則,如果我下線,該腳本實際上是越來越調用,但在此之後,該單聲道運行時崩潰,這個錯誤

堆棧跟蹤:

at (wrapper managed-to-native) Mono.Mozilla.Base.gluezilla_evalScript (intptr,string) <0x00004>  
    at (wrapper managed-to-native) Mono.Mozilla.Base.gluezilla_evalScript (intptr,string) <0x00004>  
    at Mono.Mozilla.Base.EvalScript (Mono.WebBrowser.IWebBrowser,string) <IL 0x0001a, 0x00038>  
    at Mono.Mozilla.DOM.Document.InvokeScript (string) <IL 0x00007, 0x00017>  
    at System.Windows.Forms.HtmlDocument.InvokeScript (string,object[]) [0x00054] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\HtmlDocument.cs:143  
    at WindowsFormsHost.Form1.ShowMsg (string) <IL 0x0002b, 0x000ac>  
    at WindowsFormsHost.Form1.testToolStripMenuItem_Click (object,System.EventArgs) <IL 0x00008, 0x0001c>  
    at System.Windows.Forms.ToolStripItem.OnClick (System.EventArgs) [0x0001c] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\ToolStripItem.cs:1002  
    at System.Windows.Forms.ToolStripMenuItem.OnClick (System.EventArgs) [0x000a5] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\ToolStripMenuItem.cs:267  
    at System.Windows.Forms.ToolStripMenuItem.HandleClick (System.EventArgs) [0x00000] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\ToolStripMenuItem.cs:539  
    at System.Windows.Forms.ToolStripItem.FireEvent (System.EventArgs,System.Windows.Forms.ToolStripItemEventType) [0x00042] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\ToolStripItem.cs:1776  
    at (wrapper remoting-invoke-with-check) System.Windows.Forms.ToolStripItem.FireEvent (System.EventArgs,System.Windows.Forms.ToolStripItemEventType) <IL 0x00034, 0x00061>  
    at System.Windows.Forms.ToolStrip.OnMouseUp (System.Windows.Forms.MouseEventArgs) [0x00047] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\ToolStrip.cs:960  
    at System.Windows.Forms.ToolStripDropDown.OnMouseUp (System.Windows.Forms.MouseEventArgs) [0x00000] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\ToolStripDropDown.cs:630  
    at System.Windows.Forms.Control.WmLButtonUp (System.Windows.Forms.Message&) [0x0007e] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\Control.cs:5592  
    at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message&) [0x0017b] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\Control.cs:5329  
    at System.Windows.Forms.ScrollableControl.WndProc (System.Windows.Forms.Message&) [0x00000] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\ScrollableControl.cs:807  
    at System.Windows.Forms.ToolStrip.WndProc (System.Windows.Forms.Message&) [0x00000] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\ToolStrip.cs:1213  
    at System.Windows.Forms.ToolStripDropDown.WndProc (System.Windows.Forms.Message&) [0x0001a] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\ToolStripDropDown.cs:722  
    at System.Windows.Forms.Control/ControlWindowTarget.OnMessage (System.Windows.Forms.Message&) [0x00000] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\Control.cs:234  
    at System.Windows.Forms.Control/ControlNativeWindow.WndProc (System.Windows.Forms.Message&) [0x00000] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\Control.cs:215  
    at System.Windows.Forms.NativeWindow.WndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) [0x00085] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\NativeWindow.cs:242  
    at System.Windows.Forms.XplatUIWin32.InternalWndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) [0x00031] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\XplatUIWin32.cs:1946  
    at (wrapper native-to-managed) System.Windows.Forms.XplatUIWin32.InternalWndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) <IL 0x00021, 0x00073>  
    at (wrapper managed-to-native) System.Windows.Forms.XplatUIWin32.Win32DispatchMessage (System.Windows.Forms.MSG&) <0x00004>  
    at (wrapper managed-to-native) System.Windows.Forms.XplatUIWin32.Win32DispatchMessage (System.Windows.Forms.MSG&) <0x00004>  
    at System.Windows.Forms.XplatUIWin32.DispatchMessage (System.Windows.Forms.MSG&) [0x00000] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\XplatUIWin32.cs:2146  
    at System.Windows.Forms.XplatUI.DispatchMessage (System.Windows.Forms.MSG&) [0x00000] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\XplatUI.cs:605  
    at System.Windows.Forms.Application.RunLoop (bool,System.Windows.Forms.ApplicationContext) [0x0036a] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\Application.cs:984 
    at System.Windows.Forms.Application.Run (System.Windows.Forms.ApplicationContext) [0x00014] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\Application.cs:763 
    at System.Windows.Forms.Application.Run (System.Windows.Forms.Form) [0x00000] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\Managed.Windows.Forms\System.Windows.Forms\Application.cs:742 
    at WindowsFormsHost.Program.Main() <IL 0x00013, 0x00044> 
    at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <IL 0x0001b, 0x0003a> 

此應用程序已請求運行時終止它在一種不尋常的方式 有關更多信息,請聯繫應用程序的支持團隊。

回答

2

它應該可以工作,但不幸的是,每次mozilla拋出更新時,事情都會比我想要的更多。你在windows或linux上做這個嗎?你安裝了哪個xulrunner版本?

+0

此問題出現在Windows上,單機版本2.6.7 - 檢查Xulrunner版本後會回來。謝謝 – amazedsaint 2010-10-05 16:59:30