Welcome Guest!

If you do not have an account yet on The Web Squeeze forums, please Register! It’s FREE and there are many benefits:

  • Receive Fast Advice
  • Learn Programming Languages
  • Get Professional Website Reviews
  • Quick Troubleshooting Assistance
The Web Squeeze

> Confirm You Would Like To Close New Thread Windows

This is a discussion on Confirm You Would Like To Close New Thread Windows, within the Feedback section. This forum and the thread "Confirm You Would Like To Close New Thread Windows" are both part of the Feedback category.

 
Reply to this topicStart new topic
> Confirm You Would Like To Close New Thread Windows
Jason
post Sep 3 2008, 05:09 PM
Post #1


Master of the Universe
Group Icon

Posts: 1,298
Joined: 15-February 08
From: London, England


Could we have a JavaScript confirm when a new topic page is closed and something is entered into the content box. It is a rare occurrence but twice now I have accidentally closed down a thread I have been working on.


--------------------
Go to the top of the page
 
+Quote Post
Jacob
post Sep 3 2008, 08:21 PM
Post #2


Co-Founder
Group Icon

Posts: 2,664
Joined: 13-February 08
From: On the forum!


Hmmmm, I actually think I've done this a few times as well. It's super annoying, and you can never recreate that master piece again....lol. I don't know JavaScript, or even if this is possible....Luke? Do you think this is possible?


--------------------
Thanks,
Jacob
Go to the top of the page
 
+Quote Post
Rakuli
post Sep 3 2008, 08:55 PM
Post #3


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


CODE
// Assuming jQuery is available
$(document).ready(function() {

$('textarea, input').change(function()
{
     $(window).unload(function (e)
     {
              if (confirm('Are you sure you would like to move away from this page? You changes will be lost'))
                      return true
               else
                      e.preventDefault();
      }
}

});

// Assuming jQuery is not available

var elements = document.getElementsByTagName('*');

var nm = elements.length;

for (i=0; i<nm; i++)
{
       if (elements[i].tagName == 'TEXTAREA' || elements[i].tagName == 'INPUT')
       {
                 elements[i].currentChangeFunction = elements[i].onchange;
                
                 elements[i].onchange = function () {
                                                                      window.onunload = function () { return confirm('Are you sure you would like to move away from this page? You changes will be lost'); };
                                                                      this.currentChangeFunction();
                                                                    };
        }
}


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
Jacob
post Sep 3 2008, 09:26 PM
Post #4


Co-Founder
Group Icon

Posts: 2,664
Joined: 13-February 08
From: On the forum!


Okay, I added that code....however, it does not appear to be working. sad.gif


--------------------
Thanks,
Jacob
Go to the top of the page
 
+Quote Post
Rakuli
post Sep 3 2008, 09:32 PM
Post #5


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


Hmm.. I went to the reply page and viwed source but couldn't see it anywhere or in any of the files with other jQuery stuff.

It could be that jQuery is in noConflict mode as well?


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
Jacob
post Sep 3 2008, 10:10 PM
Post #6


Co-Founder
Group Icon

Posts: 2,664
Joined: 13-February 08
From: On the forum!


It's in there...

CODE
<script type="text/javascript" src="jscripts/ips_editor_confirm.js"></script>


--------------------
Thanks,
Jacob
Go to the top of the page
 
+Quote Post
Rakuli
post Sep 3 2008, 11:04 PM
Post #7


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


QUOTE (Jason @ Sep 4 2008, 08:09 AM) *
Could we have a JavaScript confirm when a new topic page is closed and something is entered into the content box. It is a rare occurrence but twice now I have accidentally closed down a thread I have been working on.


Ah! biggrin.gif

You only need to use one half of that script -- the top half if jQuery is on the forum and the bottomw half if not -- jQuery is there so you would use...

CODE
$(document).ready(function() {

$('textarea, input').change(function()
{
     $(window).unload(function (e)
     {
              if (confirm('Are you sure you would like to move away from this page? You changes will be lost'))
                      return true
               else
                      e.preventDefault();
      });
});

});


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
Jacob
post Sep 3 2008, 11:35 PM
Post #8


Co-Founder
Group Icon

Posts: 2,664
Joined: 13-February 08
From: On the forum!


Okay, well now it works. However, if you click okay it still moves pages, as well as cancel. Weird.


--------------------
Thanks,
Jacob
Go to the top of the page
 
+Quote Post
Rakuli
post Sep 3 2008, 11:53 PM
Post #9


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


CODE
$(document).ready(function() {

$('textarea, input').change(function()
{
     $(window).bind('unload,close', function (e)
     {
              if (confirm('Are you sure you would like to move away from this page? You changes will be lost'))
                      return true
               else {
                      e.preventDefault();
                      return false;
               }
      });
});

});


Maybe that will help?


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
Monie
post Sep 4 2008, 12:16 AM
Post #10


Squeeze Machine
*****

Posts: 733
Joined: 13-February 08
From: Borneo


Where is this for me to test? biggrin.gif


--------------------

Go to the top of the page
 
+Quote Post
Antti
post Sep 4 2008, 12:33 AM
Post #11


Rapid Squeezer
Group Icon

Posts: 308
Joined: 15-February 08
From: Finland


Click "Add Reply" and then click a link to away from that page. I guess Jacob hasn't made the latest change yet. Is it possible to extend this to browser's back button as well?


--------------------
Go to the top of the page
 
+Quote Post
Jason
post Sep 4 2008, 04:47 AM
Post #12


Master of the Universe
Group Icon

Posts: 1,298
Joined: 15-February 08
From: London, England


This is firing when the form is submitted, this is obviously incorrect as submitting the form is the goal of posting.


--------------------
Go to the top of the page
 
+Quote Post
Rakuli
post Sep 4 2008, 05:23 AM
Post #13


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


QUOTE (Jason @ Sep 4 2008, 07:47 PM) *
This is firing when the form is submitted, this is obviously incorrect as submitting the form is the goal of posting.


CODE
$(document).ready(function() {

$('textarea, input').change(function()
{
     $(window).bind('unload,close', function (e)
     {
              if (confirm('Are you sure you would like to move away from this page? You changes will be lost'))
                      return true
               else {
                      e.preventDefault();
                      return false;
               }
      });
});

$('form").submit( function () { $(window).unbind('unload,close'); });
$('input[type="submit"]').click( function () { $(window).unbind('unload,close'); });

});


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
Jason
post Sep 4 2008, 08:12 AM
Post #14


Master of the Universe
Group Icon

Posts: 1,298
Joined: 15-February 08
From: London, England


The preview button needs to be removed from this as well biggrin.gif

Also there is something weird happening in FF3. It asks if I want to navigate away from the page. I then click OK x amount of times. Nothing happens, it just keeps asking. Then I have to press cancel for the amount of times I clicked ok + 1 to move away from the page. Is anyone else having this?


--------------------
Go to the top of the page
 
+Quote Post
Rakuli
post Sep 4 2008, 08:27 AM
Post #15


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


The code hasn't changed since Jacob's last reply so everything is as it was.


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
Jacob
post Sep 4 2008, 02:58 PM
Post #16


Co-Founder
Group Icon

Posts: 2,664
Joined: 13-February 08
From: On the forum!


I've changed it, but it appears not to be working at all now.


--------------------
Thanks,
Jacob
Go to the top of the page
 
+Quote Post
Rakuli
post Sep 4 2008, 05:50 PM
Post #17


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


QUOTE (Jacob @ Sep 5 2008, 05:58 AM) *
I've changed it, but it appears not to be working at all now.


I'm confused... I changed the script and uploaded it and it appears to work but there is another confirm element coming from somewehere with the text "Are you sure you would like to navigate away from this page. Press OK to confirm"

Anyone know where that is?


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
Rakuli
post Sep 4 2008, 08:15 PM
Post #18


Squeeze Machine
Group Icon

Posts: 766
Joined: 13-February 08
From: Catching the squeezed drips downunder.


I turned the code off for you -- by commenting code out, there will be no messages at this stage until I can figure out where the second confirm message is coming from (that now no longer appears that I have commented out by code) -- odd


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
If you found The Web Squeeze to be helpful, please donate so we can keep this site FREE, FRESH, and fortified with Web Design & Development info!
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   8 Mark 592 10th March 2008 - 04:33 PM
Last post by: Jacob