[英]How to debug JavaScript code of a page from WPF WebBrowser Control
I have a WPF WebBrowser control which I used in my wpf client application to navigate to different pages. 我有一个WPF WebBrowser控件,我在我的wpf客户端应用程序中使用它来导航到不同的页面。 It has basic functionalities like back , forward , go events which calls this.webbrowser.goback(), this.webbrowser.goforward(), this.webbrowser.go().
它具有基本功能,如back,forward,go事件,调用this.webbrowser.goback(),this.webbrowser.goforward(),this.webbrowser.go()。
Though the web application works fine with IE which means all the forward and back navigations for more than one level .More than one level navigation doesn't work fine in my WPF application for one page(Billings which has contacts link and in contacts page we have address link.) when clicking back button on my address page it goes to contacts page but clicking back button on contacts page doesn't go to billing page. 虽然Web应用程序可以正常使用IE,这意味着所有前进和后退导航都超过一个级别。多个级别导航在我的WPF应用程序中不能正常工作一个页面(Billings有联系人链接和联系人页面中我们有地址链接。)当点击我的地址页面上的后退按钮时,它会转到联系人页面,但点击联系人页面上的后退按钮不会转到结算页面。
Since it's working fine in IE without any issues I suspect there is something wrong with my WPF applications . 由于它在IE中工作正常而没有任何问题,我怀疑我的WPF应用程序有问题。 I have few questions here .
我这里有几个问题。
my control looks like below 我的控制如下所示
<WebBrowser x:Name="webBrowser" DockPanel.Dock="Bottom" Navigating="webBrowser_Navigating" Navigated="webBrowser_Navigated" LoadCompleted="webBrowser_LoadCompleted"/>
And code behind looks like below: 后面的代码如下所示:
private void backButton_Click(object sender, RoutedEventArgs e)
{
// Navigate to the previous HTML document, if there is one
if (this.webBrowser.CanGoBack)
{
this.webBrowser.GoBack();
}
else
{
MessageBox.Show("Cannot go back. There needs to be something in the history to go back to.");
}
}
private void forwardButton_Click(object sender, RoutedEventArgs e)
{
// Navigate to the next HTML document, if there is one
if (this.webBrowser.CanGoForward)
{
this.webBrowser.GoForward();
}
else
{
MessageBox.Show("Cannot go Forward. There needs to be something in the history to go forward to.");
}
}
I would have expected the WebBrowser control's navigation to work in the same way as it is essentially IE hosted in WPF. 我原本期望WebBrowser控件的导航工作方式与它本质上是在WPF中托管的IE一样。
You can have the JavaScript call methods in the .NET application, so could have the JavaScript write debug info to the .NET console 您可以在.NET应用程序中使用JavaScript调用方法,因此可以将JavaScript调试信息写入.NET控制台
This class can be passed to JavaScript in WebBrowser for it to call .NET method: 这个类可以传递给WebBrowser中的JavaScript,以便它调用.NET方法:
[ComVisible(true)]
public class ScriptManager
{
// This method can be called from JavaScript.
public void WriteConsole(string output)
{
// Call a method on the form.
Console.WriteLine(output);
}
}
Pass to WebBrowser: 传递给WebBrowser:
webBrowser1.ObjectForScripting = new ScriptManager();
I don't know the JavaScript bit to call the method as I've never really used JavaScript, BUT I think it would be something like this: 我不知道调用该方法的JavaScript位,因为我从未真正使用过JavaScript,但我认为它会是这样的:
$scope.LogBackNavigation = function() {
window.external.WriteConsole("Back Navigation");
}
That might allow you to see whats happening in your JavaScript. 这可能会让你看到你的JavaScript中发生了什么。
Debug -Attach to Process - > Script Code这已经加载了我VS中的所有JS文件,我可以在任何地方放置断点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.