Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi
Created September 20, 2012 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-hiroshi/3754750 to your computer and use it in GitHub Desktop.
Save s-hiroshi/3754750 to your computer and use it in GitHub Desktop.
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