How to redirect page inside iframe to another one but we must stay in iframe

不羁的心 提交于 2020-07-31 13:59:51

问题


Could anyone help me? Is it possible to code this? Redirect page inside iframe to another one but we must stay in iframe . Without influence to parent site. I tried many scripts but nothing worked. Here is main code which i use. width and height is only for testing. I use HTML5 sandbox to prevent iframe breaks to main site. I need that to hide referer. Now parent site is showed as referer in iframed site, but i want to first site in iframe was used as referer to redirected one. Maybe it is crap, but i need that.

<!DOCTYPE html>
<html>
<body>


<iframe  width="1025" height="350" sandbox="allow-same-origin allow-scripts allow-popups allow-forms" src="URL"; </iframe>

</body>
</html>

回答1:


If you want the script to run from the frame:

document.location.href = "http://...";

If you want the parent page to redirect (change) the frame location:

HTML:

<iframe name="myFrame" ... />

JavaScript:

window.frames["myFrame"].location = "http://..."



回答2:


$(function() {
    if ('app' !== $('body').attr('id')){
        window.setTimeout(function(){
            window.top.location.href = 'your redirect url'; 
        }, 5000);
    }
});

in IFRAME use

sandbox="allow-top-navigation allow-scripts allow-forms"


来源:https://stackoverflow.com/questions/28159920/how-to-redirect-page-inside-iframe-to-another-one-but-we-must-stay-in-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!