c# - How to Inject JavaScript in WebView? -
Please do I need help for JavaScript injection in WebView in WebView.
I'm trying to come up with a webvive that responds to the click event (note: HTML is not mine from the webview, and it is dynamically generated). Unfortunately, one click event does not respond accordingly. So I have been given the option to reply to the events of HTML elements from WebViz. Up to now, I found this code:
Wait WebView.InvokeScriptAsync ("eval", new [] {"var signButton = document.getElementById (\" MyButton \ ");" + " "+" SignButton.addEventListener {"signButton.addEventListener (\" click \ ", MyButtonClicked, incorrect);" + "} and {" + "signButton.attachEvent ('onclick', MyButtonClicked);" + "}" + "Function MyBurnClite () {" + "window.external.notify ('%%' + location.href);" + "}"}); I modified it to get it in my code:
Wait WebView.InvokeScriptAsync ("eval", new [] {"var BodyEl = document "+" if (bodyEl [0] .addEventListener) {"+" bodyEl [0] .addEventListener (\ "click \", videclotted, incorrect); "+"} and "+" BodyEl [0] .attachEvent ('onclick', videoclite); "+"} "+" function videoquite () {"+" window.external.notify ('VideoClick'); "+"} "}); and this code is considered to respond to window.external.notify ('VideoClick'):
Private Zero WebView_ScriptNotify (Object Sender, NotifyEventArgs E) {var url = e.Value; } When executed, I expect the URL to be 'VideoClick', this method is never called when I stepped through the code.
Insert the code javascript, but, unfortunately, I'm not getting any exceptions and the way I'm expecting it is not working, and it seems that the Javascript function is just calling .
I also tried to use the AllowedScriptNotifyUris method on the example example but it does not clearly work with the Windows 8.1 app.
Create the function in the HTML file:
& lt; Html & gt; & Lt; Top & gt; & Lt ;! - Head goes here - & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt ;! - Body goes here - & gt; & Lt; Script type = "text / javascript" & gt; Var signButton = document.getElementById ("MyButton"); If (signButton.addEventListener) {signButton.addEventListener ("click", MyButtonClicked, Incorrect); } Other {signButton.attachEvent ('onclick', MyButtonClicked); } MyButtonClicked () function {window.external.notify ('%%' + location.href); } & Lt; / Script & gt; & Lt; / Body & gt; & Lt; / Html & gt; And call it with your code: Wait WebView.InvokeScriptAsync ("eval", new [] {"MyButtonClicked ();"});
Comments
Post a Comment