admin管理员组文章数量:1327581
Two friends of mine have tested a project I have been working on which relies on the use of the WebBrowser control, and have managed to e across a constant scenario in which the WebBrowser control is unable to execute any JavaScript on the contained web page.
For the sake of narrowing it down I created a new Windows Forms project that contains only a WebBrowser control, and tries to navigate to the following page: .html
The result on my friends puter was the below (click to enlarge):
As you can see, it doesn't render ANYTHING when trying to call the JS specific code, alternatively if you view it in a web browser with JS disabled or enabled, you'll see something.
He exported his registry keys that contain the setting for JavaScript being enabled (see ) and the value for 1400 in each of the keys matches the same settings I use, and when I run the program I have no issue.
The code for the entire test project is as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Shown(object sender, EventArgs e)
{
this.webBrowser1.Navigate(".html");
}
}
}
If a new project is created using this code that targets the 4.5 framework (either on my machine or his) it works, however if one is created using 4.0 or lower the above result occurs. I'm not sure if this is a coincidence or if it is indeed something to do with the problem / solution.
It should be noted that if he navigates to this page in Internet Explorer there are no issues, it detects that JavaScript is enabled, this problem solely resides in this test application and the main project that it is a part of.
Any help would be appreciated, I've spent a good two months trying to figure this out and still can't.
Two friends of mine have tested a project I have been working on which relies on the use of the WebBrowser control, and have managed to e across a constant scenario in which the WebBrowser control is unable to execute any JavaScript on the contained web page.
For the sake of narrowing it down I created a new Windows Forms project that contains only a WebBrowser control, and tries to navigate to the following page: http://javatester/javascript.html
The result on my friends puter was the below (click to enlarge):
As you can see, it doesn't render ANYTHING when trying to call the JS specific code, alternatively if you view it in a web browser with JS disabled or enabled, you'll see something.
He exported his registry keys that contain the setting for JavaScript being enabled (see https://gist.github./4699943) and the value for 1400 in each of the keys matches the same settings I use, and when I run the program I have no issue.
The code for the entire test project is as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Shown(object sender, EventArgs e)
{
this.webBrowser1.Navigate("http://javatester/javascript.html");
}
}
}
If a new project is created using this code that targets the 4.5 framework (either on my machine or his) it works, however if one is created using 4.0 or lower the above result occurs. I'm not sure if this is a coincidence or if it is indeed something to do with the problem / solution.
It should be noted that if he navigates to this page in Internet Explorer there are no issues, it detects that JavaScript is enabled, this problem solely resides in this test application and the main project that it is a part of.
Any help would be appreciated, I've spent a good two months trying to figure this out and still can't.
Share Improve this question edited Nov 5, 2018 at 16:07 Baptiste Candellier 1,0029 silver badges17 bronze badges asked Feb 3, 2013 at 0:48 user1243584user1243584 10-
1
I don't believe that the framework version should be an issue. I've done projects in 3.5 that JavaScript works fine on. I do know that because of other issues I've had with the standard
WebBrowser
control I've moved a lot of my projects to use WebKit (WebKit is the layout engine of Chrome and Safari). It's a great tool and they've really tried to make it similar to the standard control. If I were you I'd at least check it out. WebKit – Leon Newswanger Commented Feb 3, 2013 at 4:41 - @LeonNewswanger - This is slightly off topic, but: I have previously looked in to switching to WebKit, however some of the future requirements of the project are that we can call back into the assembly from JavaScript using the ObjectForScripting property, and I've never been able to find such a thing in WebKit; have you ever e across this in WebKit? – user1243584 Commented Feb 3, 2013 at 12:30
- I've honestly never looked, sorry. I realize it isn't really an answer to you question. That's why I posted it as a ment, and as I was unaware of your other requirements, I thought it may be something that could help you resolve your issue. – Leon Newswanger Commented Feb 3, 2013 at 17:39
- There have been other things in the past with WebKit that I've had to delve into the interop itself to find however, because a big part of the WebKit packages are just wrapper classes basically. – Leon Newswanger Commented Feb 3, 2013 at 17:41
- 1 The meta tag solution may be of interest. IE7 be default stackoverflow./questions/4612255/… – Adz Commented Apr 18, 2015 at 4:06
2 Answers
Reset to default 0From my tests WebBrowser with .NET 4 reports a web browser agent string of IE 7.0. Therefore, check your JavaScript works correctly in IE7 first.
The scripts do not load if you are using the webbrowser control.Document Text property. It perfectly fine with the Navigate method. I need the document text property to work as i get html from third party. The same html content work perfectly fine if i create an html file out of it and open it in the regular IE browser. The webbrowser control is buggy.
本文标签: cJavaScript not executing in NET WebBrowser controlStack Overflow
版权声明:本文标题:c# - JavaScript not executing in .NET WebBrowser control - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742167553a2426110.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论