- ちょっと込み入ったことをやろうとして、JavaScript で Browser Window を開く
- 開発環境/テスト環境ではおけ。(いつだったかポップアップブロック解除してた)
- 本番環境に出してみたらポップアップ Block された。(@_@;)
みたいな時に確認する項目
あまり関係ないけど公式情報
Trusted Event
Events that are generated by the user agent, either as a result of user interaction, or as a direct result of changes to the DOM, are trusted by the user agent with privileges that are not afforded to events generated by script through the createEvent() method, modified using the initEvent() method, or dispatched via the dispatchEvent() method. The isTrusted attribute of trusted events has a value of true, while untrusted events have a isTrusted attribute value of false.
要約
- ユーザー操作によってに生成されたイベント1は、信頼された物として特別な権限をもって扱われる。
- 一方で、script によって生成されたイベント2は特別な権限を持たない。
-
isTrusted
属性でわかる。
Block されないために
試して見た。。
- ajax のコールバックの中でも
isTrusted = true
(まじか。。。まぁそう覚えておくか) - ajax のコールバックの中で
window.open
するとポップアップブロックされる(期待値)。async:false
にした場合は、ブロックされない(期待値)
うーん。isTrusted
が参考になるかとおもったらそれもあるけど、もちろんイベントタイプも見てるんですね。
とりあえず ajax 結果で window.open
したい場合、 async:false
を付ければいけるっていうのは、そりゃそうなんですが。結局これはなに切っ掛けにしてるんだろう。。。。