LoginSignup
2
1

More than 5 years have passed since last update.

意図しない Popup Blocker を以下に回避する方法で色々調べたこと随時更新

Last updated at Posted at 2018-04-28
  1. ちょっと込み入ったことをやろうとして、JavaScript で Browser Window を開く
  2. 開発環境/テスト環境ではおけ。(いつだったかポップアップブロック解除してた)
  3. 本番環境に出してみたらポップアップ 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 されないために

試して見た。。

  1. ajax のコールバックの中でも isTrusted = true (まじか。。。まぁそう覚えておくか)
  2. ajax のコールバックの中で window.open するとポップアップブロックされる(期待値)。async:false にした場合は、ブロックされない(期待値)

うーん。isTrusted が参考になるかとおもったらそれもあるけど、もちろんイベントタイプも見てるんですね。

とりあえず ajax 結果で window.open したい場合、 async:false を付ければいけるっていうのは、そりゃそうなんですが。結局これはなに切っ掛けにしてるんだろう。。。。

脚注


  1. または、DOM の直接の変更によって生成されたイベント。 

  2. createEvent() で生成された関数や initMethod() 関数で変更されたイベント、dispatchEvent() 関数で dispatch されたイベント。 

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1