Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8604619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:37:05+00:00 2026-06-12T02:37:05+00:00

I’m using JQuery to handle changes in unsaved form data, user enters the page,

  • 0

I’m using JQuery to handle changes in unsaved form data, user enters the page, edits the data, tries to leave the page without saving and it sort of works since I’m getting the dialog when I’ve changed the form:
enter image description here

Above says: “Do you want to leave this page? You have unsaved data, do you want to conitnue without saving your changes?”

It works well and is a lot of functionality in very little code:

<script>
    $(function() {
        // Set the unload message whenever any input element get changed.
        $(':input').on('change', function() {
            setConfirmUnload(true);
        });

        // Turn off the unload message whenever a form get submitted properly.
        $('form').on('submit', function() {
            setConfirmUnload(false);
        });
    });

    function setConfirmUnload(on) {
        var message = "Vill du gå vidare utan att spara eventuella ändringar?";
        window.onbeforeunload = (on) ? function() { return message; } : null;
    }
</script>

Compared to what I’m using, the above looks like something much better to work on than my current combination of Java + JS that uses a hidden form variables for whether the form data was changed and then tests on both Java and JS to enable the warning which is according to my specification:

enter image description here

The above is the way it should look like. Thing is, I want the user to be able to change the form and submit it to the page without getting the warning and I’d also like to exclude the searchbox “fastseach” from the warning so is it possible to exclude components? And how do I change the display of the dialog to my own? My own dialog is drawn like this:

    // is this necessary?
    function doAsk(title, msg, action, command, actionNo, commandNo, search) {  
        document.getElementById("fastsearch").value = search;
        document.actionForm.saveStatus.value = ''
        var funcYes = 'doYes()';
        var funcNo = 'hideDialog()';
        if (title == 'Fel') {
            var s = "<div style=\"position:absolute; z-index:1000001; left:15%; top:75%; font-size: 70% \"><input id=\"dialogaterga\" style=\"font-family:calibri; width:70px; float:right; margin-right:35px;\" type=button onclick=\"javascript:"
                    + funcNo + "\" value=\"Återgå\" /></div>";
            showDialog(title, msg + s);
        } else if (title == 'Varning') {
                var v = "<div style=\"position:absolute; z-index:1000001; left:15%; top:75%\"><input  style=\"font-family:calibri; width:70px\" type=button onclick=\"javascript:"
                        + funcNo
                        + "\" value=\"Nej\" /></div><div style=\"position:absolute; left:70%; top:75%\"><input  id=\"dialogwarnyes\" style=\"font-family:calibri; width:70px\" type=button onclick=\"javascript:doSubmit('"
                        + action + "','" + command + "'); \" value=\"Ja\" /></div>";
            showDialog(title, msg + v);
        } else if (title == 'Information') {
            var i = "<div style=\"position:absolute; z-index:1000001; left:70%; top:75%\"><input type=button class=\"dialogbuttonlink\" id=\"dialogstang\" onclick=\"javascript:hideDialog()\" value=\"St&auml;ng\" /></div>";
            showDialog(title, msg + i, true);
        } else if (title == 'Fel2') {
            title = 'Fel';
            var s2 = "<div style=\"position:absolute; z-index:1000001; left:15%; top:75%; font-size: 70% \"><input id=\"dialogaterga\" style=\"font-family:calibri; width:70px; float:right; margin-right:35px;\" type=button onclick=\"javascript:"
                    + funcNo + "\" value=\"OK\" /></div>";
            showDialog(title, msg + s2);
        }
        initFocus();    
    }
function showDialog(title, message, autohide) {
    //alert("showdialog");
    var type = 'prompt';
    var dialog;
    var dialogheader;
    var dialogclose;
    var dialogtitle;
    var dialogcontent;
    var dialogmask;
    var link1
    var link2

    if (!document.getElementById('dialog')) {
        dialog = document.createElement('div');
        dialog.id = 'dialog';
        link2 = document.createElement('a');
        link2.id = 'modalFocusLink';
        link2.setAttribute('onclick', 'return false');
        link2.setAttribute('onblur', 'redirectFocus');
        link2.setAttribute('href', '#');
        dialog.appendChild(link2);
        dialogheader = document.createElement('div');
        dialogheader.id = 'dialog-header';
        dialogtitle = document.createElement('div');
        dialogtitle.id = 'dialog-title';
        dialogclose = document.createElement('div');
        dialogclose.id = 'dialog-close'
        dialogcontent = document.createElement('div');
        dialogcontent.id = 'dialog-content';
        dialogmask = document.createElement('div');
        dialogmask.id = 'dialog-mask';
        document.body.appendChild(dialogmask);
        document.body.appendChild(dialog);
        dialog.appendChild(dialogheader);
        dialogheader.appendChild(dialogtitle);
        dialogheader.appendChild(dialogclose);
        dialog.appendChild(dialogcontent);
        dialogclose.setAttribute('onclick', 'hideDialog()');
        dialogclose.onclick = hideDialog;
        link1 = document.createElement('a');
        link1.id = 'modalBlurLink';
        link1.setAttribute('onclick', 'return false');
        link1.setAttribute('onfocus', 'redirectFocus');
        link1.setAttribute('href', '#');

        dialog.appendChild(link1);

    } else {
        dialog = document.getElementById('dialog');
        dialogheader = document.getElementById('dialog-header');
        dialogtitle = document.getElementById('dialog-title');
        dialogclose = document.getElementById('dialog-close');
        dialogcontent = document.getElementById('dialog-content');
        dialogmask = document.getElementById('dialog-mask');
        dialogmask.style.visibility = "visible";
        dialog.style.visibility = "visible";
    }
    dialog.style.opacity = .00;
    dialog.style.filter = 'alpha(opacity=0)';
    dialog.alpha = 0;
    var width = pageWidth();
    var height = pageHeight();
    var left = leftPosition();
    var top = topPosition();
    var dialogwidth = dialog.offsetWidth;
    var dialogheight = dialog.offsetHeight;
    var topposition = 33;// top + (height / 3) - (dialogheight / 2);
    var leftposition = width - dialogwidth - 30; // left + (width / 2) -
                                                    // (dialogwidth / 2);
    dialog.style.top = topposition + "px";
    dialog.style.left = leftposition + "px";
    dialogheader.className = type + "header";
    dialogtitle.innerHTML = title;
    dialogcontent.className = type;
    dialogcontent.innerHTML = message;
    var content = document.getElementById(WRAPPER);
    dialogmask.style.height = content.offsetHeight + 'px';

    if (title == 'Information') {
        dialog.alpha = 100;
        dialog.style.opacity = (1.0);
        dialog.style.filter = 'alpha(opacity=' + 100 + ')';
        dialog.style.visibility = "visible";
        dialogmask.style.visibility = "hidden";
        var fodi = document.getElementById("dialogstang");
        fodi.focus();
    } else {
        if (title == 'Fel') {
            var fo = document.getElementById("dialogaterga");
            fo.focus();
        } else if (title == 'Varning') {
            var vafo = document.getElementById("dialogwarnyes");
            vafo.focus();
        }
        dialog.timer = setInterval("fadeDialog(1)", TIMER);

        if (autohide) {
            dialogclose.style.visibility = "hidden";
            // window.setTimeout("hideDialog()", (autohide * 1000));
        } else {
            dialogclose.style.visibility = "visible";
        }
        if (title == 'invisible')
            dialog.style.visibility = "hidden";
    }

}

The component I’d like to exclude could be the “update” button since pressing “update” should not activate the warning, only leaving the page. Can you help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:37:06+00:00Added an answer on June 12, 2026 at 2:37 am

    There is no way to change the look of that browse-away warning dialog. It is a native facility provided by the browser. In fact, on Firefox as of version 4 you can’t even customize the message by supplying your own string as the return value, rather it always says something like:

    “This page is asking you to confirm that you want to leave – data you have entered may not be saved.”

    As for excluding various components on your page from the browse-away warning, isn’t that simply a matter of extending the technique that you already appear to be using, where you disable the onbeforeunload event in your user event handlers? For example, when clicking the update button or the search button, you can first make sure to “un-hook” the onbeforeunload event by assigning it to null or a no-op function.

    By the way, looking at all that raw DOM construction you are doing (all the appendChild() calls and setAttribute() calls, etc), I suggest you take a look at some client-side template frameworks. Here’s a decent-looking list of alternatives. Also Angular.js from Google is pretty cool too, although not just a templating system per se.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.