1
我想禁用javascript警报在WPF(的Windows Presentation Foundation)在WPFWPF的C#禁用JavaScript警告
JavaScript警告 Wpf Image
但是,我不想取消对web浏览器的JavaScript警报
阿勒特的JavaScript web浏览器上 Webbrowser Image
WPF
private void ClickOKButton()
{
IntPtr hwnd = FindWindow("#32770", "Web sayfasından ileti");
hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Button", "OK");
uint message = 0xf5;
SendMessage(hwnd, message, IntPtr.Zero, IntPtr.Zero);
}
public MainWindow()
{
InitializeComponent();
wbBrowser.Navigate(new Uri("http://localhost/AlertWebProject"));
wbBrowser.LoadCompleted += WbBrowserOnLoadCompleted;
wbBrowser.Navigated += WbBrowser_Navigated;
}
private void WbBrowser_Navigated(object sender, NavigationEventArgs e)
{
ClickOKButton();
}
private void WbBrowserOnLoadCompleted(object sender, NavigationEventArgs navigationEventArgs)
{
ClickOKButton();
}
的JavaScript
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
function test() {
alert("Test");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<button onclick="test();">Test</button>
<p>dsadsadas</p>
</div>
</form>
</body>
</html>
因此,当他们在WPF WebBrowser控件中时,想要抑制警报,但是当它们位于常规Web浏览器窗口(例如Chrome)中时,它们会取消警报?你最好的选择可能是在你的WPF应用程序中注入一些JavaScript来重新定义'alert' –
@MattBurland这听起来像个好主意。如果你做出了答案,我会赞成它;) – AndyJ