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