问题描述
我正在使用Web浏览器控件从网站获取一些信息.它具有详细信息链接,单击该链接会打开一个弹出窗口,并在Web浏览器中显示详细信息.
I am using a webbrowser control to get some information from a website. It has a detail link, which when clicked, opens a popup window and shows the details in the webbrowser.
如果单击webbrowser控件(按程序)中的链接打开另一个窗口并显示执行错误,该怎么办.
How can I do these if click the link in webbrowser control (by program) open another window and showing execution error.
但是在资源管理器中它正在工作.而且我注意到,仅当我在Internet Explorer中打开主页时,详细信息链接才起作用,否则,如果我直接从Internet Explorer调用详细信息URL,它也会给我同样的错误.
But in explorer it is working. And I noticed that detail link works only if I open the main page in Internet Explorer, otherwise if I call the detail URL directly from Internet Explorer, it also gives me the same error.
推荐答案
我最近遇到了一种非常相似的情况.就我而言,弹出式浏览器未共享嵌入式浏览器的会话.我要做的是捕获NewWindow事件并取消它,然后将预期的URL发送到嵌入式浏览器.我需要使用ActiveX浏览器实例,因为它为您提供了尝试启动的URL.这是我的代码:
I recently ran across a very similar situation. In my case, the popup browser didn't share the session of the embedded browser. What I had to do was capture the NewWindow event and cancel it, then send the intended URL to the embedded browser. I needed to use the ActiveX browser instance because it gives you the URL that was attempting to launch. Here is my code:
您需要将Microsoft Internet Controls COM引用添加到您的项目中,以使其正常工作.
You will need to add the Microsoft Internet Controls COM reference to your project for this to work.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// this assumes that you've added an instance of WebBrowser and named it webBrowser to your form
SHDocVw.WebBrowser_V1 axBrowser = (SHDocVw.WebBrowser_V1)webBrowser.ActiveXInstance;
// listen for new windows
axBrowser.NewWindow += axBrowser_NewWindow;
}
void axBrowser_NewWindow(string URL, int Flags, string TargetFrameName, ref object PostData, string Headers, ref bool Processed)
{
// cancel the PopUp event
Processed = true;
// send the popup URL to the WebBrowser control
webBrowser.Navigate(URL);
}
}
这篇关于弹出窗口Web浏览器控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!