Javascript iframe:如何从iframe本身内部更改iframe src?
我知道有人问过一些类似于这个的问题,但我仍然没有得到正确的概念。我目前正在通过javascript以以下方式加载iframe: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)时,它会
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;