locked
Iframe page alert while clicking on Menu from parent page RRS feed

  • Question

  • User-1378722245 posted

    Hi There,

    I have ASP.NET Page wherein placed an iframe below the menu bar. When user click on any menu in the parent page, the corresponding menu page will be loaded in the iframe. 

    Now the issue is, i have one page which is used to capture details through lot of textbox , dropdown etc., and many update button present in that same page. user forget to click on update button sometimes hence i would like to show an alert when user click on menu from the parent page before saving the data. While leaving the Iframe page i need to show warning/alert message to user in case if the data is not saved / always when they leave. How to achieve this ? 

    How to achieve this? 

    Thanks in Advance 

    Ram

    Tuesday, April 24, 2018 5:02 PM

Answers

  • User-1838255255 posted

    Hi Ramganeshv,

    According to your description and needs, maybe you want to show alert message when blur to the iframe, i make a sample through your needs, please check the following sample code: 

    <head>
        <meta charset="utf-8" />
        <title></title>
        <script>
            function setit() {
                if (document.all) {
                    document.getElementById("myframe").attachEvent("onblur", dothis);
                } else {
                    document.getElementById("myframe").contentWindow.addEventListener("blur", dothis, false);
                }
            }
            function dothis() {
                alert("blurred");
            }
        </script>
    </head>
    <body onload="setit()">
        <iframe width="155" height="144" id="myframe"></iframe>
        <input />
    </body>

    Best Regards,

    Eric Du 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 25, 2018 7:21 AM

All replies

  • User-1838255255 posted

    Hi Ramganeshv,

    According to your description and needs, maybe you want to show alert message when blur to the iframe, i make a sample through your needs, please check the following sample code: 

    <head>
        <meta charset="utf-8" />
        <title></title>
        <script>
            function setit() {
                if (document.all) {
                    document.getElementById("myframe").attachEvent("onblur", dothis);
                } else {
                    document.getElementById("myframe").contentWindow.addEventListener("blur", dothis, false);
                }
            }
            function dothis() {
                alert("blurred");
            }
        </script>
    </head>
    <body onload="setit()">
        <iframe width="155" height="144" id="myframe"></iframe>
        <input />
    </body>

    Best Regards,

    Eric Du 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 25, 2018 7:21 AM
  • User-492460945 posted

    Hi Ramganeshv,

    You can use window.onbeforeunload in javascript to alert users when leaving out of the current page.Please check the below script.

    window.onbeforeunload = function() {
       return "Are you sure you want to leave?";
    };

    Below are two links which better explain its usage.

    Thanks,

    RajeshV.

    Wednesday, April 25, 2018 8:39 AM