0

First of all, not that good with Javascript. So if you have an answer, please use a fully working script.

I am trying to build a personal web page, which acts as a browser. (part of a larger system) So I need a back and forward button. Found alot of (older) articles, which all don't work for me, and the ones who did work, didn't work well.

Tryed many things, but I want to use a function to control things. I found out that I should use the history.back() thingy, and it did work once for the main page, from within a direct button. (can't seem to get it to work from inside a function)

So here is my code so far:

<!DOCTYPE html>
<html>
<body>


<iframe align="center" width="100%" height="20%" src="http://www.google.nl" frameborder=yes scrolling="yes" name="iframe" id="iframe"> </iframe>

<button type="button" onclick="ownBack()">Click me</button>

<script type="text/javascript">
function ownBack() {

    var x = document.getElementById('iframe');
    var y = (x.contentWindow || x.contentDocument);
y.history.back();
}
</script>

</body>
</html>

*PS: Using latest firefox, and got the "ignore X-frame options" plugin, so google and all other pages should work in iframes. You might want to change the url for the iframe while testing.

Pietertje
  • 43
  • 1
  • 7

2 Answers2

0

Have you tried this?

    iframe.contentWindow.history.go(-1);
    iframe.contentWindow.history.go(1);
  • 1
    Yes, tryed to add it in several positions. Didn't work for me. Added it in the ownBack function, and tryed to add it to the onclick event. Tryed different things to get the iframe data, so I could change the history thingy. Can't seem to get it to work. (back and forward could be used instead of the go thingy, according to several tutorials) – Pietertje Jan 21 '16 at 17:46
0

The error:

SecurityError: Blocked a frame with origin from accessing a cross-origin frame.

More about this and a workaround here: SecurityError: Blocked a frame with origin from accessing a cross-origin frame

It works for me in Chrome if I run it with option --disable-web-security.

Community
  • 1
  • 1
drinovc
  • 481
  • 4
  • 15