简体   繁体   English

从iframe中的脚本重定向整个页面的任何方式

[英]any way of redirecting the whole page from script inside iframe

As the topic says, Im looking for a way to redirect to another page, when i click a link in the iframe. 正如主题所说,当我单击iframe中的链接时,我正在寻找一种重定向到另一个页面的方法。 i dont want just the iframe to redirect, but the whole window. 我不希望只是iframe重定向,而是整个窗口。 is this possible? 这可能吗?

preferrably in javascript or in asp.net if possible 最好在javascript或asp.net中(如果可能)

EDIT: When i try the answers i get redirected to the source of the iframe, not to the source of the site the iframe lies on... Ill show you the code 编辑:当我尝试答案时,我将重定向到iframe的源,而不是iframe所在的网站的源。。。请向您显示代码

            function redirect() {
                window.top.location.href = "./Nyheter.html";
            }

As i dont want the code to be static, so that i can use it on many pages without changing the url, i want to do it this way, alt. 由于我不希望代码是静态的,因此我可以在很多页面上使用它而无需更改url,因此我想以这种方式进行操作,alt。 get the url from db... but preferrably this way, Solution? 从数据库获取URL ...但是最好以这种方式,解决方案? Also, forgot to mention. 另外,忘了提。 The pages are not on the same domain, they are on different ones.. this could cause some problems. 这些页面不在同一域上,它们在不同的域上..这可能会导致一些问题。

<a href="http://google.com" target="_parent">Click me!</a>

You cannot use the window.top.location if your frame and the top level page are on different domains. 如果您的框架和顶层页面位于不同的域上,则不能使用window.top.location。 A similar answer . 类似的答案

javascript: window.top.location.href = "xxx"

You should see this question which is pretty much identical: Redirect parent window from an iframe action 您应该看到几乎相同的问题: 从iframe动作重定向父窗口

I don't believe you can do it in ASP.net because this has to be done on the client side (ie. Javascript). 我不相信您可以在ASP.net中做到这一点,因为这必须在客户端(即Javascript)上完成。

window.top.location.href = "http://site.com";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM