gpt4 book ai didi

javascript - WPF 离屏 Web 浏览器控件 - 页面加载时的 Javascript 不起作用

转载 作者:行者123 更新时间:2023-11-28 00:40:17 25 4
gpt4 key购买 nike

我正在尝试使用 wpf 中的 WebBrowser 控件导航到 aspx。该页面有一个关于 onload 的 javascript。如果我将控件放在网格上并使控件的可见性折叠或隐藏,则 JavaScript 调用将起作用,但我只想要离屏调用。有办法做到这一点还是不可能的事吗?

aspx:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function OnloadJSCall() {
window.PageMethods.Docall(onSuccess, onFailure);
}

function onSuccess(result) {

}


function onFailure(error) {

}

</script>
</head>
<body>
<form id="form1" runat="server">
<div><asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>
<script language="JavaScript"> OnloadJSCall();</script>
</div>
</form>
</body>
</html>

public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

[System.Web.Services.WebMethod]
public static string Docall()
{
using (var fs = new FileStream("C:\\AD\\Test1111.txt", FileMode.Append, FileAccess.Write))
using (var sw = new StreamWriter(fs))
{
sw.WriteLine(System.DateTime.Now);
}

return "Done";
}
}

WPF App

<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>

</Grid>
</Window>

MainWindow.xaml.cs

  public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();

var webBrowserControl = new WebBrowser();
webBrowserControl.Navigate("http://localhost:53288/WebForm1.aspx");
webBrowserControl.Navigated += webBrowserControlOnNavigated;
}

private void webBrowserControlOnNavigated(object sender, NavigationEventArgs navigationEventArgs)
{
}
}

最佳答案

好的,我得到答案了。如果没有 ui 组件,那么 Javascript 将无法工作。因此将控件添加到表单中并且它起作用了!!

        var newForm =new Form();

var webBrowserControl = new System.Windows.Forms.WebBrowser();
webBrowserControl.Navigate("http://localhost:53288/WebForm1.aspx");

newForm.Controls.Add(webBrowserControl);

关于javascript - WPF 离屏 Web 浏览器控件 - 页面加载时的 Javascript 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28031562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com