可以实现
在窗体中添加Web Browser控件, 在项目引用中再添加Microsoft HTML Object Library在按钮上写代码:
foreach ( InternetExplorer ie in new ShellWindows() )
{
if( ie.Document is mshtml.HTMLDocument)
{
mshtml.HTMLDocument c = ie.Document as mshtml.HTMLDocument;
mshtml.IHTMLWindow2 hh = c.parentWindow;
if(hh.opener != null)
{
MessageBox.Show(c.title + " " + c.url + " " + "是打开的新窗口");
}
else
MessageBox.Show("非新窗口" + c.title + " " + c.url );
}
}
在窗体中添加Web Browser控件, 在项目引用中再添加Microsoft HTML Object Library在按钮上写代码:
foreach ( InternetExplorer ie in new ShellWindows() )
{
if( ie.Document is mshtml.HTMLDocument)
{
mshtml.HTMLDocument c = ie.Document as mshtml.HTMLDocument;
mshtml.IHTMLWindow2 hh = c.parentWindow;
if(hh.opener != null)
{
MessageBox.Show(c.title + " " + c.url + " " + "是打开的新窗口");
}
else
MessageBox.Show("非新窗口" + c.title + " " + c.url );
}
}
try {
var t = window.opener.location;
alert('new window');
location.href='myasp.aspx?window=new';
}
catch {
alert('window opened');
}
</script>
try {
var t = window.opener.location;
alert('opened window');
}
catch {
alert('new window');
location.href='myasp.aspx?window=new';
}
</script>