invokescript https://www.e-learn.cn/tag/invokescript zh-hans WP8.1 InvokeScript Error https://www.e-learn.cn/topic/2827807 <span>WP8.1 InvokeScript Error</span> <span><span lang="" about="/user/178" typeof="schema:Person" property="schema:name" datatype="">孤街醉人</span></span> <span>2019-12-23 19:13:15</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I am working on a Windows Phone 8.1 App. I have a problem with the InvokeScript method of the WebBrowser class. I have this in my XAML: </p> <p>And when I run this code:</p> <pre><code>myWebBrowser.Loaded += (object sender, RoutedEventArgs e) =&gt; { webBrowser.IsScriptEnabled = true; webBrowser.InvokeScript("eval", "alert('foo')"); }; </code></pre> <p>I get a System.SystemException on the line with InvokeScript that tells me this:</p> <blockquote> <p>An unknown error has occurred. Error: 80020006.</p> </blockquote> <p>When I run the same code for Windows Phone 8 (not 8.1) I don't get the exception.</p> <p>Any ideas why I get an error with WP 8.1?</p> <br /><h3>回答1:</h3><br /><p>I found the solution here.</p> <p>The Loaded event is called too early. I used the LoadCompleted event instead. As long as I navigate to something (I've been putting <em>webBrowser.NavigateToString("");</em> ) the LoadCompleted event will be called only when the WebBrowser control has fully loaded content.</p> <p>Here is the new code :</p> <pre><code>webBrowser.LoadCompleted += (object sender, NavigationEventArgs e) =&gt; { webBrowser.IsScriptEnabled = true; webBrowser.InvokeScript("eval", "alert('foo');"); }; </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/24611226/wp8-1-invokescript-error</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/c" hreflang="zh-hans">c#</a></div> <div class="field--item"><a href="/tag/invokescript" hreflang="zh-hans">invokescript</a></div> </div> </div> Mon, 23 Dec 2019 11:13:15 +0000 孤街醉人 2827807 at https://www.e-learn.cn How to call a jQuery function from .NET WebBrowser control using InvokeScript()? https://www.e-learn.cn/topic/2588197 <span>How to call a jQuery function from .NET WebBrowser control using InvokeScript()?</span> <span><span lang="" about="/user/139" typeof="schema:Person" property="schema:name" datatype="">删除回忆录丶</span></span> <span>2019-12-18 05:55:45</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>Had a Windows Forms app using a WebBrowser control (.NET 4) to load a web page that communicated with the app. I had a call to <code>InvokeScript()</code> to call a Javascript routine in the web page at one point.</p> <p>Now things have been "updated", and jQuery is now being used. So instead of having a <code>OnVenueSelected()</code> function to call, it's now some <code>$.city.venue.onVenueSelected: function(param)</code> oddity.</p> <p>Simply changing my call from <code>InvokeScript("OnVenueSelected", new object[] { params })</code> to <code>InvokeScript("$.city.venue.onVenueSelected", new object[] { params })</code> did not work. I don't get any observable errors or exceptions, but the logic in the call is not invoked. </p> <p>Some digging around had me trying to use <code>eval</code> as the call and passing the function name and parameters as the string to <code>eval</code>. That didn't work either. </p> <p>Is there a known way to invoke a function that's embedded in a couple of layers of jQuery magic?</p> <p>Thanks.</p> <br /><h3>回答1:</h3><br /><p>OK - I get to answer my own question. Thanks in part to the answer by at How to call a jQuery function from .NET WebBrowser control using InvokeScript()?, I was able to change my call to the jQuery function to </p> <pre><code>string[] codeString = { String.Format(" {0}('{1}') ", @"$.city.venue.onVenueSelected", result.ToString()) }; this.myBrowser.Document.InvokeScript("eval", codeString); </code></pre> <p>Amazingly enough, this seems to be working.</p> <p>In my case, the result variable is of type <code>bool</code> (in case that matters to anyone).</p> <br /><br /><br /><h3>回答2:</h3><br /><p>For those that may not be aware, you can also use .execScript in pre-.NET versions of WB control and current/.NET versions of WB control. You can also choose the language of the script you want to execute, ie: "JScript" or "VBScript". Here is the one liner:</p> <pre><code>WebBrowser1.Document.parentWindow.execScript "alert('hello world');", "JScript" </code></pre> <br /><br /><br /><h3>回答3:</h3><br /><p>Yeah, that is probably the quickest way to do that, because the 'invokescript' simply needs to be given a name of a global function. So after pushing the functions down deeper into some structures, and to still be able to call them via InvokeScript in a "more pretty" way, you would have to, for example, write a single GLOBAL wrapper (a 'dispatcher' would be a better name), similar to the:</p> <pre><code>function callme(what, args) { var actualfunction = eval(what); // or any other way to parse the 'what' and get a function return actualfunction(args); } </code></pre> <p>and later call it:</p> <ul><li><p>from JS:</p> <pre><code>callme("$.city.venue.onVenueSelected", ..args..) </code></pre> <p>(but I truly dont know why you could want to call it from JS :))</p></li> <li><p>and from CS:</p> <pre><code>browser.InvokeScript("callme", new string[]{ "$.city.venue.onVenueSelected", ..args.. }) </code></pre></li> </ul><p>this way, I think you would be able to pass objects as function arguments directly, without stringifying them</p> <p>..but from my experience, in &gt;80% of the cases, you just need to pass some simple numbers and strings or setup flags, so all that hassle is usually just a code bloat</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/9188063/how-to-call-a-jquery-function-from-net-webbrowser-control-using-invokescript</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/jquery" hreflang="zh-hans">jquery</a></div> <div class="field--item"><a href="/tag/webbrowser-control" hreflang="zh-hans">webbrowser-control</a></div> <div class="field--item"><a href="/tag/invokescript" hreflang="zh-hans">invokescript</a></div> </div> </div> Tue, 17 Dec 2019 21:55:45 +0000 删除回忆录丶 2588197 at https://www.e-learn.cn How to call a jQuery function from .NET WebBrowser control using InvokeScript()? https://www.e-learn.cn/topic/2588131 <span>How to call a jQuery function from .NET WebBrowser control using InvokeScript()?</span> <span><span lang="" about="/user/213" typeof="schema:Person" property="schema:name" datatype="">我们两清</span></span> <span>2019-12-18 05:55:07</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>Had a Windows Forms app using a WebBrowser control (.NET 4) to load a web page that communicated with the app. I had a call to <code>InvokeScript()</code> to call a Javascript routine in the web page at one point.</p> <p>Now things have been "updated", and jQuery is now being used. So instead of having a <code>OnVenueSelected()</code> function to call, it's now some <code>$.city.venue.onVenueSelected: function(param)</code> oddity.</p> <p>Simply changing my call from <code>InvokeScript("OnVenueSelected", new object[] { params })</code> to <code>InvokeScript("$.city.venue.onVenueSelected", new object[] { params })</code> did not work. I don't get any observable errors or exceptions, but the logic in the call is not invoked. </p> <p>Some digging around had me trying to use <code>eval</code> as the call and passing the function name and parameters as the string to <code>eval</code>. That didn't work either. </p> <p>Is there a known way to invoke a function that's embedded in a couple of layers of jQuery magic?</p> <p>Thanks.</p> <br /><h3>回答1:</h3><br /><p>OK - I get to answer my own question. Thanks in part to the answer by at How to call a jQuery function from .NET WebBrowser control using InvokeScript()?, I was able to change my call to the jQuery function to </p> <pre><code>string[] codeString = { String.Format(" {0}('{1}') ", @"$.city.venue.onVenueSelected", result.ToString()) }; this.myBrowser.Document.InvokeScript("eval", codeString); </code></pre> <p>Amazingly enough, this seems to be working.</p> <p>In my case, the result variable is of type <code>bool</code> (in case that matters to anyone).</p> <br /><br /><br /><h3>回答2:</h3><br /><p>For those that may not be aware, you can also use .execScript in pre-.NET versions of WB control and current/.NET versions of WB control. You can also choose the language of the script you want to execute, ie: "JScript" or "VBScript". Here is the one liner:</p> <pre><code>WebBrowser1.Document.parentWindow.execScript "alert('hello world');", "JScript" </code></pre> <br /><br /><br /><h3>回答3:</h3><br /><p>Yeah, that is probably the quickest way to do that, because the 'invokescript' simply needs to be given a name of a global function. So after pushing the functions down deeper into some structures, and to still be able to call them via InvokeScript in a "more pretty" way, you would have to, for example, write a single GLOBAL wrapper (a 'dispatcher' would be a better name), similar to the:</p> <pre><code>function callme(what, args) { var actualfunction = eval(what); // or any other way to parse the 'what' and get a function return actualfunction(args); } </code></pre> <p>and later call it:</p> <ul><li><p>from JS:</p> <pre><code>callme("$.city.venue.onVenueSelected", ..args..) </code></pre> <p>(but I truly dont know why you could want to call it from JS :))</p></li> <li><p>and from CS:</p> <pre><code>browser.InvokeScript("callme", new string[]{ "$.city.venue.onVenueSelected", ..args.. }) </code></pre></li> </ul><p>this way, I think you would be able to pass objects as function arguments directly, without stringifying them</p> <p>..but from my experience, in &gt;80% of the cases, you just need to pass some simple numbers and strings or setup flags, so all that hassle is usually just a code bloat</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/9188063/how-to-call-a-jquery-function-from-net-webbrowser-control-using-invokescript</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/jquery" hreflang="zh-hans">jquery</a></div> <div class="field--item"><a href="/tag/webbrowser-control" hreflang="zh-hans">webbrowser-control</a></div> <div class="field--item"><a href="/tag/invokescript" hreflang="zh-hans">invokescript</a></div> </div> </div> Tue, 17 Dec 2019 21:55:07 +0000 我们两清 2588131 at https://www.e-learn.cn C# Webbrowser.invokeScript and Error: 80020006 only in this particular site https://www.e-learn.cn/topic/2414486 <span>C# Webbrowser.invokeScript and Error: 80020006 only in this particular site</span> <span><span lang="" about="/user/177" typeof="schema:Person" property="schema:name" datatype="">天涯浪子</span></span> <span>2019-12-13 00:36:40</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I have tried to goole solutions for hours...</p> <p>I'm doing an app for windowsphone, which is used to show public transport details. I need to change values of WhereFrom and WhereTo and click submit in the tinyurl webpage and then scrape the info. If you can recommend any other way to do this, please tell it. I have also tried webclient, httpwebrequest, but their instructions and examples are way too complicated for me.</p> <p>I'm stuck with the error mentioned before and the selain.InvokeScript("eval"); line causes it. Even stranger is that I only got this error in this tinyurl website. eg when using www.bing.com site I have another error: 80020101 using the third Invokescript line.</p> <pre><code>using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls; using System.Runtime.InteropServices; //COMException namespace PhoneApp5 { public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { InitializeComponent(); //selain as WebBrowser. It's instanted in mainpage.xaml selain.IsScriptEnabled = true; selain.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(selain_LoadCompleted); selain.Navigating +=new EventHandler&lt;NavigatingEventArgs&gt;(selain_Navigating); string osoite = "http://tinyurl.com/c7xel8s"; //string osoite = "http://bing.fi"; selain.Navigate(new Uri(osoite)); } private void selain_Navigating(object sender, NavigatingEventArgs e) { } private void selain_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) { //Updates textblock in mainpage tekstiBlokki.Text = "READY"; } private void button1_Click(object sender, RoutedEventArgs e) { try { selain.InvokeScript("eval"); selain.InvokeScript("eval", "document.getElementById('keya')"); selain.InvokeScript("eval", "document.getElementById('sb_form_q').value = 'Roadname';"); //selain.InvokeScript("eval", "document.getElementById('keyb').value=\"" + textBox2.Text + '\"'); } catch (ObjectDisposedException) { MessageBox.Show("Selain ei ole enää toiminnassa"); } catch (InvalidOperationException) { MessageBox.Show("Reference not found"); } catch (COMException) { MessageBox.Show("Vastaavaa Jscript funktiota ei löydy"); } } } } </code></pre> <br /><h3>回答1:</h3><br /><p>You are trying to invoke a script called <strong>eval</strong> in all pages. The second parameter is the <strong>argument</strong> for the <strong>eval</strong> function. Chances are, there is no <strong>eval</strong> function available on the page, therefore you get an exception. </p> <p>Review the docs for InvokeScript here.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/10200661/c-sharp-webbrowser-invokescript-and-error-80020006-only-in-this-particular-site</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/c" hreflang="zh-hans">c#</a></div> <div class="field--item"><a href="/tag/windows-phone-7" hreflang="zh-hans">windows-phone-7</a></div> <div class="field--item"><a href="/tag/browser" hreflang="zh-hans">browser</a></div> <div class="field--item"><a href="/tag/invokescript" hreflang="zh-hans">invokescript</a></div> </div> </div> Thu, 12 Dec 2019 16:36:40 +0000 天涯浪子 2414486 at https://www.e-learn.cn How to call a jQuery function from .NET WebBrowser control using InvokeScript()? https://www.e-learn.cn/topic/627860 <span>How to call a jQuery function from .NET WebBrowser control using InvokeScript()?</span> <span><span lang="" about="/user/202" typeof="schema:Person" property="schema:name" datatype="">醉酒当歌</span></span> <span>2019-11-29 10:19:21</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><div class="alert alert-danger" role="alert"> <p>Had a Windows Forms app using a WebBrowser control (.NET 4) to load a web page that communicated with the app. I had a call to <code>InvokeScript()</code> to call a Javascript routine in the web page at one point.</p> <p>Now things have been "updated", and jQuery is now being used. So instead of having a <code>OnVenueSelected()</code> function to call, it's now some <code>$.city.venue.onVenueSelected: function(param)</code> oddity.</p> <p>Simply changing my call from <code>InvokeScript("OnVenueSelected", new object[] { params })</code> to <code>InvokeScript("$.city.venue.onVenueSelected", new object[] { params })</code> did not work. I don't get any observable errors or exceptions, but the logic in the call is not invoked. </p> <p>Some digging around had me trying to use <code>eval</code> as the call and passing the function name and parameters as the string to <code>eval</code>. That didn't work either. </p> <p>Is there a known way to invoke a function that's embedded in a couple of layers of jQuery magic?</p> <p>Thanks.</p> </div><div class="panel panel-info"><div class="panel-heading">GuyWithDogs</div><div class="panel-body"> <p>OK - I get to answer my own question. Thanks in part to the answer by at <a href="https://stackoverflow.com/questions/9188063/how-to-call-a-jquery-function-from-net-webbrowser-control-using-invokescript" rel="nofollow">How to call a jQuery function from .NET WebBrowser control using InvokeScript()?</a>, I was able to change my call to the jQuery function to </p> <pre><code>string[] codeString = { String.Format(" {0}('{1}') ", @"$.city.venue.onVenueSelected", result.ToString()) }; this.myBrowser.Document.InvokeScript("eval", codeString); </code></pre> <p>Amazingly enough, this seems to be working.</p> <p>In my case, the result variable is of type <code>bool</code> (in case that matters to anyone).</p> </div></div><div class="panel panel-info"><div class="panel-heading"></div><div class="panel-body"> <p>For those that may not be aware, you can also use .execScript in pre-.NET versions of WB control and current/.NET versions of WB control. You can also choose the language of the script you want to execute, ie: "JScript" or "VBScript". Here is the one liner:</p> <pre><code>WebBrowser1.Document.parentWindow.execScript "alert('hello world');", "JScript" </code></pre> </div></div><div class="panel panel-info"><div class="panel-heading">quetzalcoatl</div><div class="panel-body"> <p>Yeah, that is probably the quickest way to do that, because the 'invokescript' simply needs to be given a name of a global function. So after pushing the functions down deeper into some structures, and to still be able to call them via InvokeScript in a "more pretty" way, you would have to, for example, write a single GLOBAL wrapper (a 'dispatcher' would be a better name), similar to the:</p> <pre><code>function callme(what, args) { var actualfunction = eval(what); // or any other way to parse the 'what' and get a function return actualfunction(args); } </code></pre> <p>and later call it:</p> <ul><li><p>from JS:</p> <pre><code>callme("$.city.venue.onVenueSelected", ..args..) </code></pre> <p>(but I truly dont know why you could want to call it from JS :))</p></li> <li><p>and from CS:</p> <pre><code>browser.InvokeScript("callme", new string[]{ "$.city.venue.onVenueSelected", ..args.. }) </code></pre></li> </ul><p>this way, I think you would be able to pass objects as function arguments directly, without stringifying them</p> <p>..but from my experience, in &gt;80% of the cases, you just need to pass some simple numbers and strings or setup flags, so all that hassle is usually just a code bloat</p> </div></div><div class="alert alert-warning" role="alert"><p>来源:<code>https://stackoverflow.com/questions/9188063/how-to-call-a-jquery-function-from-net-webbrowser-control-using-invokescript</code></p></div></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/jquery" hreflang="zh-hans">jquery</a></div> <div class="field--item"><a href="/tag/webbrowser-control" hreflang="zh-hans">webbrowser-control</a></div> <div class="field--item"><a href="/tag/invokescript" hreflang="zh-hans">invokescript</a></div> </div> </div> Fri, 29 Nov 2019 02:19:21 +0000 醉酒当歌 627860 at https://www.e-learn.cn