user13479159
user13479159

Reputation:

IOS Safari, Check If page loads inside of iframe or not

I'm trying to check if the page loads inside of iframe of not.
I know this is a possible duplicated question, and I did check every questions about this.
those solutions worked fine with chrome and etc browsers but SAFARI.
it's driving me crazy.

i did try everything i'm possibly able to do.
but none of them worked.
Do you guys know how to check this in safari.
plz save me from this.

Upvotes: 0

Views: 1467

Answers (2)

user13479159
user13479159

Reputation:

Okay. I figured this out.
The problem i had was not about checking the iframe stuffs.

What i tried to do was if users do sth and the page is loaded inside of the iframe,
Open a new tab with a specific URL.
But window.open(); does not work in Safari. So I changed my plan to change url of parent's URL.

Checking iframes:

try {
    return window.self !== window.top;
} catch (e) {
    return true;
}

Changing parent's URL:

OpenPopUp: function(link){
        var isSafari = !!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/);
        var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;

        link = Pointer_stringify(link);

        if(isSafari && iOS) {
            window.top.location.href = link;
        }
        else{
            window.open(link, 'For iOS Users');
        }
    }

Thank you so much for those who commented and answered.
I was just too foolish about this.

Upvotes: 0

user12449933
user12449933

Reputation: 300

simple, just use onload function inside iframe

how to use it :- https://www.w3schools.com/jsref/event_onload.asp

Upvotes: 1

Related Questions