f8g

ポップアップブロック

下の二つはブラウザによって動作が違うみたいというお話でした。

button.onclick = function(){
  window.open(url);
};
button.onclick = function(){
  setTimeout(function(){
    window.open(url);
  }, 1);
};

http://arikui.github.com/js/popupblock.html

<html>
<head>
<title>test</title>
<script type="text/javascript">
function execute(){
	window.open("popupblock.html");
}

function click1(){
	execute();
}

function click2(){
	setTimeout(function(){
		execute();
	}, 1);
}

function click3(){
	var req = new XMLHttpRequest;

	req.onreadystatechange = function(){
		if(this.readyState == 4){
			execute();
		}
	};

	req.open("GET", "popupblock.html");
	req.send();
}
</script>
<body>
<button onclick="click1();">click</button>
<button onclick="click2();">setTimeout</button>
<button onclick="click3();">XMLHttpRequest</button>
<button onclick="document.getElementsByTagName('button')[0].click();">call first button's event</button>
</body>
</html>