Jump to content
php.lv forumi
  • 0

Ignorēt kodu, kad vajadzīgs formas submit.


yeahz

Question

Ir koda gabals:

	<script type="text/JavaScript">
   function goodbye(e) {
  	 if(!e) e = window.event;
  	 //e.cancelBubble is supported by IE - this will kill the bubbling process.
  	 e.cancelBubble = true;
  	 e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog

  	 //e.stopPropagation works in Firefox.
  	 if (e.stopPropagation) {
  		 e.stopPropagation();
  		 e.preventDefault();
  	 }
   }
   window.onbeforeunload=goodbye;
   </script>

Ko tas dara? - Kad esi kādā lapā, kur ir šis koda gabals, un kad mēģini iet prom no šīs lapas vai vispār aizvērt tabu / browseri, tiek izmests paziņojums par to, ka "vai tiešām vēlies pamest šo lapu?".

 

Problēma - kā lai šo gabalu ignorē lapā, kurā viņš ir un kad tiek nospiesta formas submit poga?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Aizvācot to eventu.

Iespējams, ka šādi:<pre class="prettyprint"><form onsubmit="window.onbeforeunload = function(){}; return true;"</pre>

 

Bet vispār lietot šādu kodu ir diezgan stulbi, jo tas ir sasodīti kaitonoši.

Edited by briedis
Link to comment
Share on other sites

  • 0

Paldies, šādi strādā. :)

 

Jā, es zinu, ka šāda lieta ir kaitinoša, bet tas netiks taisīts ļaunprātīgiem mērķiem. Šādu lietu es izmantošu tikai vienā pašā lapā, kad tiek pievienots raksts, jo ir gadījušās reizes netīšām kaut ko nospiest un viss darbs vējā.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...