4

この質問は以前の質問のように見えますが、少し異なります。

次のようにJavaScriptで関数を書きたい

this.imagePopup = function() {
    window.open("images/index.php","imageSelect");
    //some code I don't know....
    return imgUrl;
};

テキスト入力フィールドに値を設定 せずに、ポップアップから選択した画像の URL を変数 imgUrl に設定するには、どのコードが必要ですか?

4

2 に答える 2

2

ポップアップにjavascriptハンドラーを記述して、オープナーのメソッドを呼び出すことができます。たとえば、次のようなハンドラメソッドが役立ちます。

function onSelectedIndexChange(ddl) {
    if(opener && ddl) opener.selectImageInPopup = ddl.options[ddl.selectedIndex].value;
}

..

<select onchange="onSelectedIndexChange(this)">...

ここで、selectImageInPopupは、オープナーウィンドウのグローバル変数です。

于 2012-10-29T16:18:57.953 に答える
0

初め:

var myWindow = window.open("images/index.php","imageSelect");

画像をダンプします:

console.log(myWindow.document.images);

たとえば、必要な1つの画像の位置を見つけます(ポップアップの最初の画像)

var imgUrl = myWindow.document.images[0].src

幸運を!

于 2012-10-29T16:10:24.027 に答える