Dawn of the Macbook (personal post)

I have for some time now been sporting an HP Mini netbook, which has been at times the bane of my existence. However, today I freed myself from my enslavement and got a 13″ Macbook Pro. I also got a job doing mobile development on iOS, Android, and Blackberry. All of this means that posts about iOS will be forthcoming. I like to be well rounded.

Also sorry for the lack of posts lately. School and a new baby boy have been keeping me busy.

Keep coding!

2 Responses to Dawn of the Macbook (personal post)

  1. Chuck Clark says:

    Hello Matthew,

    I saw a post of yours at Stackoverflow about you using the window.onbeforeunload I was wondering if you could tell me why the javascript isn’t “communicating with” my form. Here’s my form and here’s the javascript:

    Email Address:

    var formHasChanged = false;
    var submitted = false;

    $(document).on(‘change’, ‘form.confirm-navigation-form input, form.confirm-navigation-form select, form.confirm-navigation-form textarea’, function (e) {
    formHasChanged = true;
    });

    $(document).ready(function () {
    window.onbeforeunload = function (e) {
    if (formHasChanged && !submitted) {
    var message = “You owe it to yourself to watch the video, otherwise \n” + “You could be losing $$$ thousands and thousands $$$! \n” + “Click ‘Stay on this page’ to Watch Video”, e = e || window.event;
    if (e) {
    e.returnValue = message;
    }
    return message;
    }
    }
    $(“form”).submit(function() {
    submitted = true;
    });
    });

    • Well first of you need to double check that you included the class “confirm-navigation-form” on your form. Without that, your “change” listener will never do anything.

      Second, your code looks like it should be correct. However I did run into an issue between Chrome and IE. In Chrome, the dialog only appears when the form has changed and the user tries to navigate away without submitting the form (which was my desired behavior). In IE, the dialog ALWAYS appears whether you navigate away or submit the form. If you want IE to behave like chrome, set window.onbeforeunload = null inside your $(“form”).submit function. If you want Chrome to behave like IE, take out the $(“form”).submit function and the submitted variable entirely.

      Good luck!

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: