WPF 浏览器调用脚本 [英] WPF browser InvokeScript
问题描述
有谁知道为什么我在尝试在 WPF 应用程序 (.Net 4) 中调用 javascript 函数时收到(来自 HRESULT 的异常:0x80020006 (DISP_E_UNKNOWNNAME))?
Does anyone know why I am getting (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME)) when attempting to invoke a javascript function in a WPF application (.Net 4)?
浏览器控件托管在应用程序中,并与本地 html 文件一起使用,例如:
The browser control is hosted inside an application and is being used with local html files, e.g:
C:\Users\XXXX\AppData\Roaming\XXXX\Books\XXXX_revision_1_1\html\1\med-9780198569244-chapter-4
C:\Users\XXXX\AppData\Roaming\XXXX\Books\XXXX_revision_1_1\html\1\med-9780198569244-chapter-4
这个文件有一个 javascript 包含 - 'script/scripts.js'
This file has a javascript include - 'script/scripts.js'
当 url 是本地文件时,是否可以从 C# 使用浏览器控件上的 InvokeScript 方法执行 javascript 函数?
Is it possible from C# to execute a javascript function using the InvokeScript method on the browser control when url is a local file?
推荐答案
简单的答案是,我提早调用它,它必须在页面加载之后.
The simple answer was, I was calling it to early, it has to be after the page has loaded.
如 MSDN 所述 - http://msdn.microsoft.com/en-us/library/cc491132.aspx
as stated in MSDN - http://msdn.microsoft.com/en-us/library/cc491132.aspx
'InvokeScript(String) 不应在实现它的文档加载完成之前调用.您可以通过处理 LoadCompleted 事件来检测文档何时完成加载.'
这篇关于WPF 浏览器调用脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!