Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.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/back按钮未更新位置。href_Javascript_Html_Iframe - Fatal编程技术网

Javascript iframe/back按钮未更新位置。href

Javascript iframe/back按钮未更新位置。href,javascript,html,iframe,Javascript,Html,Iframe,“后退和前进”按钮按我的要求控制iFrame 我正在使用onClick函数更新iFrame元素的源 <input class='home_main_submenu2' type='button' value='Training Information' OnClick='document.getElementById("home_frame").src=("http://claytonpolicetraining.blogspot.com/")'> <input class=

“后退和前进”按钮按我的要求控制iFrame

我正在使用onClick函数更新iFrame元素的源

<input class='home_main_submenu2' type='button' value='Training Information'  OnClick='document.getElementById("home_frame").src=("http://claytonpolicetraining.blogspot.com/")'>
<input class='home_main_submenu2' type='button' value='Training Resource'  OnClick='document.getElementById("home_frame").src=("/ftproot/TrainingResource/")'>

<iframe id='home_frame' class='viewPort' src='?subtopic=featured_video' name='content_frame'></iframe>

我使用一个按钮“弹出”iFrame到一个新窗口,以防用户不想使用iFrame。按钮代码:

<input id='frame_new_tab' type='button' value='Open in New Tab' onClick='OpenNewTab("home_frame")'>

function OpenNewTab(id)
{
    var redirect = "";

    try
    {
        window.event.returnValue = false;
        redirect = document.getElementById(id).contentWindow.location.href;
    }
    catch(e)
    {
        redirect = document.getElementById(id).src;
    }
    window.open(redirect);
}

函数OpenNewTab(id)
{
var=”;
尝试
{
window.event.returnValue=false;
重定向=document.getElementById(id).contentWindow.location.href;
}
捕获(e)
{
重定向=document.getElementById(id).src;
}
窗口。打开(重定向);
}
所有这些都是完美的

问题:

如果我在iFrame上打开address1,然后单击返回按钮返回iFrame上的address2,然后尝试“弹出”iFrame,它会弹出address1,这是我在单击返回按钮之前看到的,而不是我当前所在的iFrame上的address2


不知何故,当我按下back按钮时,iFrame将在iFrame中显示正确的内容,但它无法将正确的信息加载到iFrame元素,例如src。如何修复此问题?

请发布您的全部代码!哈哈哈,这就是我想弄明白的lol。但我向你发誓,当我点击后退按钮时,它就是这么做的。。。。。请编辑原始帖子,以包含应用于问题的完整代码。感谢您的回复。
iframe.src
不是
iframe.location.href
。“后退”按钮将上一页重新加载到
iframe
,主页面不会更新,您设置为
src
的值仍然存在。您必须分配
iframe.location.href
以获取
iframe
中的真实页面,但这在跨域页面中是不可能的。好的,因此只有当我从本地的“primarypage”返回到外部的“secondarypage”时才会出现问题。