Safari does not detect an exception when trying to access the parent window object using Javascript try / catch

Thus, the code below can be seen through the link to the script. Safari refuses to catch an exception - I assume it could be because it is not a "Javascript" error? In any case, if you run the code in any other browser, you will see the URL of the page in the console.

The purpose of the function is to find the URL of the page when executing multiple frames on the page. If anyone can confirm why Safari will not catch the error and / or can offer a solution, that would be great ... Thanks!

function logURL() {
    var oFrame = window, 
        exception = false;

    try {
        while (oFrame.parent.document !== oFrame.document) {
            oFrame = oFrame.parent;
        }
    } catch (e) {
        exception = true;
    }

     if(exception) {
         console.log('excepted', oFrame.document.referrer);
     } else {
         console.log('no exception', oFrame.location.href);
     }
}

http://jsfiddle.net/HPu9n/82/

+4
1

Safari, Safari, -, JavaScript . Safari undefined , -.

, oFrame.parent.document, , , , .

(JSFiddle):

function logURL() {
    var oFrame = window, 
        exception = false;

    try {
        while (oFrame.parent.document !== oFrame.document) {
            //Check if document property is accessible.
            if (oFrame.parent.document) {
                oFrame = oFrame.parent;
            }
            else {
                //If document was not set, break the loop and set exception flag.
                exception = true;
                break;
            }
        }
    } catch (e) {
        exception = true;
    }

    if(exception) {
        console.log('excepted', oFrame.document.referrer);
    } else {
        console.log('no exception', oFrame.location.href);
    }
}
logURL();

Logs:

excepted http://jsfiddle.net/ggh0a0f4/
+4

All Articles