好的,我在一个父页面内有两个iframe(出于某种原因)。
我在父页面上有一个导航菜单,可以更改iframe#1的源...
iFrame#1的作用是显示另一个导航菜单... 就像子导航菜单一样...
现在,我如何在点击iFrame#1内部的li时更改iframe#2的源?它们都在同一个父页面上...
除了惨败,Chrome Dev工具还会发出警告-
Unsafe JavaScript attempt to access frame with URL file:///C:/website/index.html from frame with URL file:///C:/website/news/navigator.html. Domains, protocols and ports must match.
这里是一些代码以使事情稍微清晰些:
HTML
我在父页面上有一个导航菜单,可以更改iframe#1的源...
iFrame#1的作用是显示另一个导航菜单... 就像子导航菜单一样...
现在,我如何在点击iFrame#1内部的li时更改iframe#2的源?它们都在同一个父页面上...
除了惨败,Chrome Dev工具还会发出警告-
Unsafe JavaScript attempt to access frame with URL file:///C:/website/index.html from frame with URL file:///C:/website/news/navigator.html. Domains, protocols and ports must match.
这里是一些代码以使事情稍微清晰些:
HTML
<!-- HTML for the parent page itself -->
<iframe id="frameone" src=""></iframe>
<iframe id="frametwo" src=""></iframe>
<button onclick="onenav('test.html')">Change 1st frame</button>
<!-- The following is the HTML that is loaded inside "frameone" -->
<button onclick="twonav('test2.html')">Change 2nd frame</button>
// Javascript
var one = document.getElementById('frameone');
var two = document.getElementById('frametwo');
function onenav(x){
one.src = x;
}
function twonav(y){
two.src = y;
}
对我来说,这是有道理的,因为所有操作都在父页面上执行... 加载时,我查询开发工具,可以看到'one'和'two'都有帧元素... 第一个按钮可以正常工作,但第二个按钮不行...