SORU
2 Aralık 2008, Salı


Javascript Tarayıcı Penceresini Kapatmadan Önce Bir Uyarı Almak İçin

Aşağıdaki kod tarayıcı penceresini kapatmadan üzerine bir uyarı almaya çalıştım:

<script language="JavaScript" type="text/javascript">
  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
    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?";
  }
</script>

Çalışır ama sayfa bir köprü varsa, o köprüyü tıklatarak aynı uyarı yükseltir. Tarayıcı penceresini kapatıyorum sadece uyarı ve köprüler üzerine tıklayarak olmadığını göstermek istiyorum.

CEVAP
2 Aralık 2008, Salı


Başka bir uygulama bu web sayfasında bulabilirsiniz şudur: http://ujap.de/index.php/view/JavascriptCloseHook

<html>
  <head>
    <script type="text/javascript">
      var hook = true;
      window.onbeforeunload = function() {
        if (hook) {
          return "Did you save your stuff?"
        }
      }
      function unhook() {
        hook=false;
      }
    </script>
  </head>
  <body>
    <!-- this will ask for confirmation: -->
    <a href="http://google.com">external link</a>

    <!-- this will go without asking: -->
    <a href="anotherPage.html" onClick="unhook()">internal link, un-hooked</a>
  </body>
</html>

Ne bir bayrak, bir değişken olarak kullanın.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Bucky Roberts

    Bucky Robert

    9 HAZİRAN 2011
  • Sali Kaceli

    Sali Kaceli

    24 ŞUBAT 2009
  • TheFlightsuit

    TheFlightsui

    22 HAZİRAN 2009