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

  • 3DS Max Tutorials

    3DS Max Tuto

    4 AĞUSTOS 2013
  • Liberator

    Liberator

    14 EYLÜL 2007
  • Makeup Lover

    Makeup Lover

    12 HAZİRAN 2011