1

ユーザーがボタンをクリックすると、ポップアップが開きます。このポップアップは保留ページに移動し、ユーザーが Web サイトを離れるかブラウザーを閉じるのを待ちます。

次に、ユーザーがブラウザを離れるか閉じると、ポップアップの場所が別のサイトにリダイレクトされます。

次のコードのいくつかのバリエーションを試しました。

win=window.open('google.com','popup'); //just to illustrate the "win" = my window.open().

$(window).bind('beforeunload', function() {
   window.win.location.href="http://the-new-location.com";
   //tried something like this as well:
   //win.location.href="http://the-new-location.com";
});

しかし、運がなければ。私は javascript /jquery に精通していないので、この作業を行う方法についての助けをいただければ幸いです。

ありがとう!

4

2 に答える 2

2

私は解決策を見つけました:

win=window.open('google.com','popup');

window.onunload = redirect;
function redirect(){
   window.win.location.href="http://the-new-url.com";
};
于 2012-04-10T13:03:02.337 に答える
1

すでにプロトタイプが機能していることは知っていますが、jquery オプションが必要な場合:

var popup = window.open('http://google.com', 'popup');

$(window).unload(function() {
    if(!popup.closed) {
        popup.location.href = 'http://surveyurl.com/';
    }
});

popup.closed があるかどうかも確認する必要があります。

于 2012-04-10T13:08:02.897 に答える