0

I have got 3 iframes and buttons «Back» and «Forward». How to make these buttons work? I tried different code, but nothing works.

enter image description here

I tried Back and forward buttons in an iframe answers, but nothing works either.

btn1.onclick = function() {
  frames[0].contentWindow.history.go(-1);
  //              or
  // iframe.contentWindow.history.back(); 
};
iframe {
  border: 1px solid navy;
  height: 300px;
  margin: 30px;
  width: 300px;
}

button {
  margin: 10px 150px;
}
<iframe src="about:blank"></iframe>
<iframe src="about:blank"></iframe>
<iframe src="about:blank" name="frame3"></iframe>
<button onclick="window.frames[0].location='https://itstep.org'">IT Step</button>
<button onclick="window.frames[1].location='https://mystat.itstep.org'">Mystat</button>
<button onclick="window.frames.frame3.location='https://quiz.itstep.org'">Quizes</button>



<button id="btn1" style="margin: 50px; margin-left: 80px;">Back</button> 
<button id="btn4" style="margin: 30px;" onclick="window.frames[0].history.go(1)">Forward</button>
<button id="btn2" style="margin: 50px; margin-left: 130px;">Back</button> 
<button id="btn5" style="margin: 30px;">Forward</button>
<button id="btn3" style="margin: 50px; margin-left: 130px;" onclick="frame3.history.back()">Back</button> 
<button id="btn6" style="margin: 30px;">Forward</button>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • What is the intended result with the "back" and "forward" buttons? If you clicked "forward" what would happen? – Harrison Aug 11 '23 at 08:30
  • 1
    Due to security reasons you cannot navigate iframes with pages from a different origin from your page. You can only change the URL but not do history.back from the parent page `Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame.` – mplungjan Aug 11 '23 at 08:31

0 Answers0