c# - WPF Browser throws error -
i calling javascript functions c# using wpf variant of browser control via invokescript.
i can call function once without problems. when call second time, throws following error :
unknown name. (exception hresult: 0x80020006 (disp_e_unknownname))
the code using following :
this.browser.loadcompleted += (sender, args) => { this.browser.invokescript("writefromexternal", new object[] { "firstcall" }); // works this.browser.invokescript("writefromexternal", new object[] { "secondcall" }); // throws error };
the javascript function :
function writefromexternal(message) { document.write("message : " + message); }
i can call c# functions page via javascript fine , invoke c#, can't invoke second time. regardless of function call.
i not understand why fail second time.
thank you
edit :
did following test (javascript) :
function pageloaded() { window.external.tick(); window.external.tick(); window.external.tick(); } window.onload = pageloaded; function writefromexternal(message) { document.write("message : " + message); }
and c# side :
private int = 0; public void tick() { invoke("writefromexternal", new object[] { "ticked"+ i++ }); } public static void invoke(string method, object[] parameters) { maininterface.browser.invokescript(method, parameters); }
and still throws same error (after first call), suggests not matter called, invoking function c# throw error if done more once.
i assume did same me , put scripts in body. reason when call document.write wpf overwrites document. if instead of using document.write append child works fine. change javascript function be:
window.writefromexternal = function (message) { var d = document.createelement("div") d.innerhtml= "message : " + message; document.body.appendchild(d); } // call c# writefromexternal("test")
Comments
Post a Comment