开发者

How to break iframe and redirect page with Jquery

How can i understand that my page is being called from iframe 开发者_如何学Pythonand break it with jquery ? Thank you.


if (self !== top)
    top.location.replace(self.location.href)

that's how you break out of a frame


This can be done in plain Javascript since top and location are both objects attached to the global window object provided in all major browsers.

if (top.location != location){
    location.href = 'http://google.com';
}


if you really want a JQuery solution here it is (Crossbrowser, and works fine even if $ is something else in the scoop):

(function($) { 

    if($(document) !== top)
    top.location.replace($(document).location.href)

})(jQuery);

Even though its unnecessary and overkill because it can be done easier with vanilla JavaScript.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜