locked
Webbrowser error when using external javascript RRS feed

  • Question

  • I see this error with both WPF and WinForms WebBrowser controls. If I link to an external javascript, I always get the following error when the browser is initially loaded.

    A runtime error has occurred.
    Do you wish to Debug?
    
    Line: 1
    Error: Invalid charactor

    I tried the most simple test case with an empty javascript file and empty html body and still get the above error.

    C# code to set up the web browser:

    WebBrowser browser = new WebBrowser();
    browser.NavigateToString(TestString);
    

    Html seen by using "View Source" after the browser is loaded and shown:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <link type="text/css" rel="stylesheet" href="file:///C:/style.css" />
    <script type="text/javascript" src="file:///C:/script.js"> </script>
    </head>
    <body> </body>
    </html>

    I can work around this by embedding the script into the same html but I would like to avoid doing that.

    Greatly appreciate any help on this matter.

    Tung.

    Friday, April 9, 2010 3:05 PM

Answers

All replies

  • This looks like a trust issue. Is your application full trust?
    Bigsby, Lisboa, Portugal
    O que for, quando for, é que será o que é...
    Wenn ist das Nunstruck git und Slotermeyer? Ja! ... Beiherhund das Oder die Flipperwaldt gersput!
    http://bigsby.eu
    Friday, April 9, 2010 3:14 PM
  • This looks like a trust issue. Is your application full trust?
    Bigsby, Lisboa, Portugal
    O que for, quando for, é que será o que é...
    Wenn ist das Nunstruck git und Slotermeyer? Ja! ... Beiherhund das Oder die Flipperwaldt gersput!
    http://bigsby.eu
    Friday, April 9, 2010 3:14 PM
  • You can inject css and javascript separately, if that's any good to you.

    http://www.codewrecks.com/blog/index.php/2009/03/11/hilite-words-in-webbrowser-now-for-wpf-control/

    Friday, April 9, 2010 3:19 PM
  • You can inject css and javascript separately, if that's any good to you.

    http://www.codewrecks.com/blog/index.php/2009/03/11/hilite-words-in-webbrowser-now-for-wpf-control/

    Friday, April 9, 2010 3:20 PM
  • Bigsby, I tried using:

    [PermissionSetAttribute(SecurityAction.LinkDemand, Unrestricted = true
    
    )]
    [PermissionSetAttribute(SecurityAction.InheritanceDemand, Unrestricted = true
    
    )]

    but it didn't work either.

     

    Andy, I have no problem with embedding the script into the html from the very beginning. The problem only happens when I link the javascript to an external file. I guess I could try to insert the <script> tag after the page is completely loaded but I would prefer a solution that doesn't need to modify the html document after the document has already been loaded.

     

    Thanks,
    Tung.

    Friday, April 9, 2010 4:36 PM
  • Hi Tung,

    I found another forum post (http://social.msdn.microsoft.com/forums/en-US/ieextensiondevelopment/thread/54544ec6-c2a5-40e5-934c-525e11df0053/) that gave some alternate solutions to this problem.  This one might work for you:

    Run regedit
    Go to this registry key:  HKLM\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BLOCK_LMZ_SCRIPT
    Add this registry value as a DWORD: MyAppName.exe (whatever your app name is)
    The default value is 0 which is what you want.

    This fixed the problem for me.

    Hope this is a workable solution for you,
    Andre

    • Marked as answer by tt2lhp Monday, April 12, 2010 2:41 PM
    Friday, April 9, 2010 7:48 PM
  • Hi Andre,

     

    That works perfectly. Thanks a lot :-D

     

    Tung.

    Monday, April 12, 2010 2:42 PM