1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

親Window画面から子Window画面にcallback関数を定義する方法

Last updated at Posted at 2018-11-13
子画面.js
var RunCallbackFunction = function() { }; //reference holder only
親画面.js
var myPopup = window.open(...);

setMyFunction = function() { myPopup.RunCallbackFunction = myFunc; };

//IE使わないならコレ
myPopup.addEventListener('load', setMyFunction, false);
//IE使うならコレ
myPopup[myPopup.addEventListener ? 'addEventListener' : 'attachEvent'](
  (myPopup.attachEvent ? 'on' : '') + 'load', setMyFunction, false
);

JavaScriptで親画面に値を渡す小窓を作る方法
https://qiita.com/shibafu/items/c71a5e93f7c3b6cebe42

ググると親画面に値を渡す方法としてwindow.openerを使う方法がたくさんヒットするが、呼び出し元でcallback関数を渡したいのに固定の関数とか。。。。

これに関する情報が日本語で全くなかったので転載。
https://stackoverflow.com/questions/3030859/detecting-the-onload-event-of-a-window-opened-with-window-open/3030893#3030893
https://stackoverflow.com/questions/2797560/set-a-callback-function-to-a-new-window-in-javascript#comment2834701_2797574
JSは盛んだけど、子Windowを立ち上げるシチュエーション自体、SIでも一部しか使わないから情報ないのかな・・・

1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?