简体   繁体   English

iframe:我们如何从iframe内部改变iframe src?

[英]iframe: How can we change iframe src from inside iframe itself?

I know there are question have been asked around resembling to this one, but still I am not getting proper concept of this. 我知道有问题围绕这个问题,但我仍然没有得到正确的概念。 I am currently loading an iframe through javascript in following manner: 我目前正在通过javascript以下列方式加载iframe:

jQuery('.out-div-login').html("<iframe id='parent' frameBorder='0' width='320' height='500' src='"+_url+"'></iframe>");  

Which is working fine. 哪个工作正常。 (its cross domain). (其跨域)。 After loading my application inside given iframe, I want to come back to original state where .out-div-login was loading iframe into parent html. 在给定的iframe中加载我的应用程序后,我想回到原始状态,其中.out-div-login正在将iframe加载到父html中。
From outside of iframe I can do this by accessing iframe using its id attribute, but not from the inside. 从iframe外部我可以通过使用其id属性访问iframe,但不能从内部访问iframe。 Is there any way I can reload the iframe by giving its src again ? 有没有什么办法可以通过再次给它的src重新加载iframe? or by above code but from inside the iframe ? 或者通过上面的代码但是来自iframe内部? Thanks. 谢谢。
Update 更新
I have tried below code without any success as of now: 我已尝试过以下代码,但目前没有任何成功:

var ifr = $('iframe[id="parent"]');  

from one of js file inside iframe with id parent . 来自id parent iframe的js文件之一。 when I do console.log(ifr) it gives in firebug something like this Object[] instead of <iframe id="parent"> 当我执行console.log(ifr)它会在firebug中提供类似于Object[]而不是<iframe id="parent">

You should use location.href inside the iframe. 您应该在iframe中使用location.href That should work. 这应该工作。 set location.href in the iframe to your new location. 将iframe中的location.href设置为新位置。

url查询字符串(?xxx)也应该保存在新的url中,因此整个解决方案应该是:

location.href = "new_link_url" + location.search;

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

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