Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am running webpage in c# browser , if i open the page in mozilla , or Internet explorer , the java script works fine , but when i use the same page in c# browser , the java script isnt running at all

What I have tried:

I have suppressed errors with this code , is this the problem ?

webBrowser1.ScriptErrorsSuppressed = true;
Posted
Updated 12-Oct-20 6:21am
Comments
F-ES Sitecore 12-Oct-20 12:02pm    
What do you mean by "c# browser"? What type is webBrowser1?

1 solution

It works fine for me.
If I add a WebBrowser control to my app, and pass it a file:
HTML
<!DOCTYPE html>
<html>
<body onload="myFunction()">

<h1>Hello World!</h1>

<script>
function myFunction() {
  document.getElementById('demo').innerHTML = Date();
}
</script>
<p id="demo"></p>
</body>
</html>

C#
private void FrmMain_Shown(object sender, EventArgs e)
    {
    myWebBrowser.Navigate(new Uri("file:///D:/Test Data/jsDemo.html"));
    }

C#
private void button1_Click(object sender, EventArgs e)
    {
    string title = myWebBrowser.DocumentTitle;
    HtmlElementCollection x = myWebBrowser.Document.GetElementsByTagName("HTML");
    string HtmlOfDocument = x[0].InnerHtml;
    string textOfDocument = x[0].InnerText;
    }

Then I get exactly what I expect:
HTML
<HEAD></HEAD>
<BODY onload=myFunction()>
<H1>Hello World!</H1>
<SCRIPT>
function myFunction() {
  document.getElementById('demo').innerHTML = Date();
}
</SCRIPT>

<P id=demo>Mon Oct 12 17:20:07 2020</P></BODY>

Hello World!
Mon Oct 12 17:20:07 2020

So what am I doing that you aren't?
 
Share this answer
 
Comments
Member 11755075 16-Oct-20 3:50am    
sorry for the late reply , so you are using a separate button , but am just using the page , and if i use the page directly in ie, or firefox or chrome , js works perfectly , but if i use in c# browser , its not running at all :(
Member 11755075 16-Oct-20 4:18am    
and i checked with basic js scripts and it works , so no problem with that , am checking my incremental php js scripts they are not working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900