Skip to content

Instantly share code, notes, and snippets.

@hirayama-evolni
Last active November 12, 2015 06:03
Show Gist options
  • Save hirayama-evolni/c785016c61ec12097c65 to your computer and use it in GitHub Desktop.
Save hirayama-evolni/c785016c61ec12097c65 to your computer and use it in GitHub Desktop.
外部URLのiframeで開いたダイアログを閉じるためのもの
$(function(){
"use strict";
// メッセージを受け取ってダイアログを閉じる
$(window).on("message", function(e){
var message = e.originalEvent.data;
message = JSON.parse(message);
if(message.message == "CLOSE_DIALOG"){
// 使うプラグインによって変えてください。
$.magnificPopup.close();
}
});
});
$(function(){
"use strict";
// 閉じるボタンがクリックされたら親ウィンドウにmessageを送る
$(".dialog_close").on("click", function(e){
e.preventDefault();
if(window.parent !== window){
// 親がいる場合のみ
var message = JSON.stringify({
message: "CLOSE_DIALOG"
});
window.parent.postMessage(message, "*");
} else {
console.log("Closing!");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment