Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi
Created Sep 20, 2012
Embed
What would you like to do?
JavaScript > iframe sample
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>インラインフレームのテスト</title>
</head>
<body>
<iframe width="200" id="frame" height="150" src="sample.html">
テスト
</iframe>
</body>
</html>
jQuery(function($) {
var frame = document.getElementById('frame');
// frameがドキュメントの読み込みを完了してからfram内要素の処理を行うためonloadイベント使う。
frame.onload = function() {
var form = frame.contentWindow.document.getElementById('form');
var submit = (function(elem) {
return function() {
window.alert('Frame Test');
return false;
};
}(form));
form.onsubmit = submit;
};
});
<!DOCTYPE html>
<html lang="ja">
<head>
<title>インライン</title>
</head>
<body>
<form id="form" action="#" method="POST">
<input type="submit" value="アラート">
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment