我正在尝试在WebView中调用一个函数.我需要调用的一些目标函数是:
play: function()
{
if (this.value < this.p.max)
{
this.inc();
this.timer = new it_timer({ object: this, method: "play", timeout: 200 });
}
else
this.stop();
},
stop: function()
{
if (this.timer)
this.timer.stop();
this.playing = false;
this.playbutton.style.backgroundPosition = "0 0";
}
Run Code Online (Sandbox Code Playgroud)
我开始打电话
webView.InvokeScript("play", new string[0]);
Run Code Online (Sandbox Code Playgroud)
但这没用,HRESULT:0x80020101.我在这个主题上找到了这个http://support.microsoft.com/kb/247784,但它根本没有帮助我.
然后我尝试在多个站点上做我发现的示例:
webView.InvokeScript("eval", new string[] { "document.documentElement.outerHTML;");
Run Code Online (Sandbox Code Playgroud)
和
webView.InvokeScript("alert", new string[] {"message"});
Run Code Online (Sandbox Code Playgroud)
但是这两个都没有用,给出了相同的HRESULT代码.WebView正常呈现,javascript在页面上正常工作.
我很感激在确定问题/寻找解决方案方面提供帮助.
编辑:似乎"警告",所有在类中声明的方法都不起作用.在早期的.NET版本中似乎有一个InvokeMethod(..),WinRT还有其他选择吗?
有一个使用WebBrowser控件(.NET 4)的Windows窗体应用程序加载与该应用程序通信的网页.我有一个呼叫要InvokeScript()在网页上调用一个Javascript例程.
现在事情已经"更新"了,现在正在使用jQuery.因此OnVenueSelected(),它不是具有调用函数,而是现在有些$.city.venue.onVenueSelected: function(param)奇怪.
单纯从改变我的电话InvokeScript("OnVenueSelected", new object[] { params })给InvokeScript("$.city.venue.onVenueSelected", new object[] { params })没有工作.我没有得到任何可观察到的错误或异常,但是没有调用调用中的逻辑.
一些挖掘让我尝试使用eval作为调用并将函数名称和参数作为字符串传递给eval.那也行不通.
有没有一种已知的方法来调用嵌入在几层jQuery魔法中的函数?
谢谢.
我正在开发Windows Phone 8.1应用程序.我有一个WebBrowser类的InvokeScript方法的问题.我在我的XAML中有这个:
当我运行此代码时:
myWebBrowser.Loaded += (object sender, RoutedEventArgs e) =>
{
webBrowser.IsScriptEnabled = true;
webBrowser.InvokeScript("eval", "alert('foo')");
};
Run Code Online (Sandbox Code Playgroud)
我在使用InvokeScript的行上得到一个System.SystemException,它告诉我:
出现未知错误.错误:80020006.
当我为Windows Phone 8(而不是8.1)运行相同的代码时,我没有得到异常.
有什么想法我为什么会在WP 8.1中出错?
好的,这很愚蠢。我加载到WebView的HTML中有一个现有变量,称为caret_position
我想通过Windows Store应用中的InvokeScriptAsync检索它。这是我尝试过的。
return await HtmlEditor.InvokeScriptAsync("eval",
new string[] { "return caret_position;" });
return await HtmlEditor.InvokeScriptAsync("eval",
new string[] { "caret_position;" });
Run Code Online (Sandbox Code Playgroud)
这些都不起作用。我可以使它工作的唯一方法是将其写入javascript中的隐藏输入中,然后使用此调用。
return await HtmlEditor.InvokeScriptAsync("eval",
new string[] { "document.getElementById('this_is_silly').value;" });
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以直接访问javascript变量,还是每次都必须跳过这些箍?