Following code displays two buttons: AJAX popup and Direct popup. They are supposed to open the same page in a new window. Direct popup calls just window.open() in onclick event. AJAX popup does AJAX call and then in stateChanged() function calls window.open() just in the same way.
Both of them work in FF, but AJAX popup doesn't in IE, it displays annoying popup warning.
I actually think I understand what is going on. Popup blockers generally allow one popup per one click. In this case the relationship between click and popup gets lost because of AJAX call. But in my case the url to open is provided by server side component via AJAX response. So I can't just get rid of the AJAX call. I also can't force the users to use FF or to alter their popup blocker settings in IE.
Any ideas or workarounds are welcome.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> popup test </title>
<script type="text/javascript">
var xmlhttp;
function loadXMLDoc(url)
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
alert ("Your browser does not support XMLHTTP!");
return;
}
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function stateChanged()
{
if (xmlhttp.readyState==4)
{
if (xmlhttp.status==200)
{
window.open('popup.html', '_blank');
}
else
{
alert("Problem retrieving XML data:" + xmlhttp.statusText);
}
}
}
</script>
</head>
<body>
<button type="button" onclick="loadXMLDoc('popup.html')">AJAX popup</button>
<button type="button" onclick="window.open('popup.html', '_blank');">Direct popup</button>
</body>
</html>