Last active
November 12, 2015 06:03
-
-
Save hirayama-evolni/c785016c61ec12097c65 to your computer and use it in GitHub Desktop.
外部URLのiframeで開いたダイアログを閉じるためのもの
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
"use strict"; | |
// メッセージを受け取ってダイアログを閉じる | |
$(window).on("message", function(e){ | |
var message = e.originalEvent.data; | |
message = JSON.parse(message); | |
if(message.message == "CLOSE_DIALOG"){ | |
// 使うプラグインによって変えてください。 | |
$.magnificPopup.close(); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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