Subscribe

Execute JavaScript

  1. 2009-07-28 11:20:34 PDT
    Hey,

    Love the control. I'm making good use of it, but I've hit a roadblock. I need a way to execute some JavaScript on the document from C# either by inserting a <script> block with some JS or by invoking it some other way. Can you recommend a way to do this? If not, are you available for a bit of contracting to add this feature?

    Thanks
    Alexei
  2. 2009-07-28 11:28:22 PDT
    Just a follow up. I see there is a method called appendChild on DOMDocument:

    webView.mainFrame().DOMDocument().appendChild(IDOMNode oldNode)

    Just wondering if there might be a way to append a script element to the DOM this way to have it execute.. any thoughts?
  3. 2009-07-28 13:02:03 PDT
    Another follow up. I've been looking at doing something like this:

    IDOMElement iEl = webView.mainFrame().DOMDocument().createElement("script");
    iEl.setAttribute("type", "text/javascript");
    IDOMText tCon = webView.mainFrame().DOMDocument().createTextNode(jsToExec);
    iEl.appendChild(tCon);
    webView.mainFrame().DOMDocument().appendChild(iEl);

    but I'm getting "not implemented" errors. Thought maybe that would be a route.
  4. 2009-07-28 13:14:09 PDT
    Heya,

    It might suffice to simply append a string onto DocumentText, i.e. 'browser.DocumentText += "<script>......."? though that seems a bit messy. It does appear that there are ways of directly accessing the DOM from code, but I haven't really looked into them yet. I had a brief look at the webView.mainFrameDocument().executeWebScript method, but as you've mentioned it seems like it's not fully implemented yet.

    I'm planning on working out this DOM stuff next, however I'll be in the wilds of Tanzania for ~2 weeks from tomorrow so I won't be able to do anything with it for a while. If you make any progress, keep me posted. :)

    Peter
  5. 2009-07-28 13:32:35 PDT
    Cool. Hey have fun in Tanzania!

    executeWebScript sounds exactly like what I'd need.

    My company is building a product that would include webkit. I'd love to use this project. When you get back from your trip and you've sorted all your photos drop me a line. If there is a way we can help you fill in the bits to get that method working I'd like to do it. We're planning to release our tool in late september.

    Cheers,
    Alexei
  6. 2009-07-28 13:57:26 PDT
    Damn:

    HRESULT STDMETHODCALLTYPE WebScriptObject::evaluateWebScript(
    /* [in] */ BSTR /*script*/,
    /* [retval][out] */ VARIANT* /*result*/)
    {
    ASSERT_NOT_REACHED();
    return E_NOTIMPL;
    }

    A lot of Scripting-Stuff seems to be incomplete in the webkit-sources (for windows) ;/
  7. 2009-07-29 10:31:33 PDT
    I found this as well. Does that mean that it's simply not possible to do client-scripting because the interfaces are not implemented in Webkit.dll? Does anybody want to tackle the job of implementing it for us on a consulting basis?

    Cheers,
    Alexei
  8. 2009-07-30 03:40:59 PDT
    stringByEvaluatingJavaScriptFromString works. ie
    webView.stringByEvaluatingJavaScriptFromString("document.body.innerHTML += 'hello';");
  9. 2011-01-11 23:38:05 PST
    I also had some problems! Please provide a running javascript sample in the WebKit.Net. If you make any progress about this problem, keep me posted. regards Thank you very much! my email is sun.weichao@yahoo.com
  10. 2011-05-19 10:15:56 PDT
    Hi, is there any chance to get javascript working ? that's only reason that i'm not using WebKit.NET :/
  11. 2011-06-21 07:47:24 PDT
    Any progress on this issue ?
  12. 2011-11-06 12:28:23 PST
    string StringByEvaluatingJavaScriptFromString(string); the function has a bug when i get a long string from javascript, it report memory error. is anyone can tell me how to fix it.
  13. 2011-12-12 06:40:24 PST
    I need also appendchild in my project. Have you managed to use this function? Thanks, Ivo
  14. 2012-03-15 12:32:19 PDT
    I also had some problems getting javascript running: First:Add a reference to WebKit.Interop. Second: do something like string test = webKitBrowser1.StringByEvaluatingJavaScriptFromString("$('#instruction').hide()"); Third: you can access the DOM directly. eg: if (webKitBrowser1.Document.FirstChild.NextSibling.TextContent.Contains("EmbeddedBrowserHasRechedTheGoal")) for Testing i've tried to execute alert('test'); - it seems that webkit.dotnet doesn't show an alert box ... -> bad idea for debugging. Good Luck, mike
Jump To:
< Previous | 1 | Next >

Add a Reply

This forum does not allow anonymous participation.

Log in to add a reply. Not registered? Create an account to participate and receive email updates when replies are posted to this topic.