Change iframe source from another iframe

Ok, I have 2 iframes inside the parent page (for any reason).

I have a navigation menu on the parent page that changes the source of iframe # 1 ...

Operation iFrame # 1 - displaying the ANOTHER navigation menu ... As a sub-navigation menu ...

Now, how can I press the li button inside iFrame # 1, change the source of iframe # 2? They are both located on the same parent page ...

Besides the unsuccessful failure, I also get a warning from Chrome Dev tools -

Insecure JavaScript is trying to access the frame with the URL file: /// C: /website/index.html from the frame with the URL file: /// C: /website/news/navigator.html. Domains, protocols, and ports must be consistent.

Here is some code to make things a little clearer:

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;
}

, ... dev, , : "" "" .. , - ...

+3
2

parent.twonav

DEMO

var links = [
    'javascript:\'<button onclick="parent.twonav(1)">Change 2nd frame</button>\'',
    'javascript:\'Hello\''
];
var one, two;
window.onload=function() {
  one = document.getElementById('frameone');
  two = document.getElementById('frametwo');
}  

function onenav(idx) {
    one.src=links[idx];
}  

function twonav(idx) {
    two.src=links[idx];
}  
+5

iframe?

parent.document.getElementById('2').src = "the new url";

- ? , iframe 2.

0

All Articles