0

I have a function in parent iframe.

var reloadFrameWindow = function() {
    "use strict";
    var doc, myFrame, keyElem, url;
    doc = document;
    myFrame = doc.getElementById("myFrame");
    keyElem = doc.getElementById("key"); 
    if (myFrame && keyElem) {
        keyElem.value = keyElem.value + "X";
        url = myFrame.src;
        url = updateQueryStringParameter(url, "key", keyElem.value);
        jQuery.ajax({
            type: "GET",
            url: url,
            success: function() {
                myFrame.src = newUrl;
            }
        });
    }
 };

In my pop up I have added

window.onbeforeunload = function() {
    "use strict";
    window.opener.reloadFrameWindow();
};
  1. If I close it on IE11, 8 the parent iframe gets reloaded.
  2. If I close it on chrome, it doesn't reload parent iframe but the key element value does increase by 1 in both cases.

Note: I want this to fire only when it closes, not when the back button is clicked. But I wouldn't mind if it happens in both cases

Chun ping Wang
  • 3,879
  • 12
  • 42
  • 53
  • `onbeforeunload` is very restrictive with regard to what is allowed and differs browser to browser. You can not control user clicking back button vs other ways window can be unloaded. It's all or none – charlietfl Mar 04 '16 at 20:31
  • Sure I would take all then none but that doesn't explain why key element value is change but parent window is never reloaded. – Chun ping Wang Mar 08 '16 at 00:53

1 Answers1

0

actually i found that doing this in chrome works..

jQuery.ajax({
                type: 'GET',
                url: newUrl,
                success: function() {
                    myFrame.src = newUrl;
                }
            }); 
Chun ping Wang
  • 3,879
  • 12
  • 42
  • 53