2012-02-25 8 views
1

私は何時間も探していて、複数のバージョンをテストして、自分の理論をテストしています。jQueryの終了ポップアップリダイレクト?

私がしようとしているのは、alertまたはconfirm(または何でもよい)を使用して、ユーザーが購入フォームからナビゲートしようとするとダイアログをポップアップすることです。私はちょうど彼らに "おい、代わりに、無料の相談を受けるのはなぜですか?"と尋ねたいと思います。ユーザーを「無料相談」フォームにリダイレクトします。

これは私がこれまで行ってきたことであり、正しい結果を得られないだけです。

$(window).bind('beforeunload', function(){ 
     var pop = confirm('Are you sure you want to leave? Why not get a FREE consultation?'); 
     if (pop) { 

      window.location.href('http://www.mydomain/free-consultation/'); 
     } else { 
      // bye bye 
     } 
    }); 

    $("form").submit(function() { 
     $(window).unbind("beforeunload"); 
    }); 
+0

注:https://bugzilla.mozilla.org/show_bug.cgi?id=588292 – Interrobang

答えて

1

beforeunloadalert()の代わりに、ユーザーのマウスがドキュメントを去ったかどうかを確認することにしました。以下のコードを参照してください:Firefoxはあなたが設定されたすべてのメッセージを無視し、独自のを表示すること

$(document).bind('mouseleave', function(event) { 
    // show an unobtrusive modal 
}); 
1

これは、ページ滞在またはままにしたい、ユーザーにダイアログを確認して見せています。正確にあなたが探しているものではありませんが、おそらくそれは始動に役立つでしょう。

function setDirtyFlag() { 
    needToConfirm = true; //Call this function if some changes is made to the web page and requires an alert 
    // Of-course you could call this is Keypress event of a text box or so... 
} 

function releaseDirtyFlag() { 
    needToConfirm = false; //Call this function if dosent requires an alert. 
    //this could be called when save button is clicked 
} 


window.onbeforeunload = confirmExit; 
function confirmExit() { 
    if (needToConfirm) 
     return "You have attempted to leave this page. If you have made any changes to the fields without clicking the Save button, your changes will be lost. Are you sure you want to exit this page?"; 
} 

スクリプトはこれを試してみてくださいhttp://forums.devarticles.com/showpost.php?p=156884&postcount=18

+0

私はちょうど滞在したくありません。ユーザーを別のページにリダイレクトしたい – dcolumbus

0

から取られた:それは役立つかどうか

window.onunload = redirurl; 
      function redirurl() { 
       alert('Check this Page'); 
       window.location.href('http://www.google.com'); 
      } 
関連する問題