Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript iframe:如何从iframe本身内部更改iframe src?_Javascript_Jquery_Iframe - Fatal编程技术网

Javascript iframe:如何从iframe本身内部更改iframe src?

Javascript iframe:如何从iframe本身内部更改iframe src?,javascript,jquery,iframe,Javascript,Jquery,Iframe,我知道有人问过一些类似于这个的问题,但我仍然没有得到正确的概念。我目前正在通过javascript以以下方式加载iframe: jQuery('.out-div-login').html("<iframe id='parent' frameBorder='0' width='320' height='500' src='"+_url+"'></iframe>"); 来自iframe中的一个js文件,id为parent。当我执行console.log(ifr)时,它会

我知道有人问过一些类似于这个的问题,但我仍然没有得到正确的概念。我目前正在通过javascript以以下方式加载iframe:

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

来自
iframe
中的一个js文件,id为
parent
。当我执行
console.log(ifr)
时,它会在firebug中提供类似以下
Object[]
的内容,而不是
您应该在iframe中使用
location.href
。这应该行得通。将iframe中的location.href设置为新位置。

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

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

感谢您的回复,@Sebi2020可能会重复,但只有当我们尝试从iframe外部执行时,给定链接中的代码才起作用。!!我尝试过这个,我甚至无法从当前
iframe
中获取
iframe
引用,因此
location.href
目标到当前文档!!对于此iframe,它是当前文档。很好,谢谢:)
location.href = "new_link_url" + location.search;