0

I am trying to create a five clicks away from Hitler game on Wikipedia. I am doing this by having players navigate from a random page in Wikipedia to the Hitler profile page. To do this, I need to record the history of the user only within the iframe. I am having difficulty doing this. So far, my code is relatively basic, but I need help recording this history. Here is my HTML so far:

<head>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <iframe id="iframe" 
           name="iframeName" src="https://en.wikipedia.org/wiki/Special:Random"></iframe>
           <script>
           console.log(document.getElementById("iframe").contentWindow.history.length);
           </script>
</body>

In response, I receive this error:

VM108:1 Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame.(…)(anonymous function) @ VM108:1InjectedScript._evaluateOn @ VM101:145InjectedScript._evaluateAndWrap @ VM101:137InjectedScript.evaluate @ VM101:118

Is this a security issue within Chrome? What is the capacity of this history method? Can it record up to five sites?

Eric Park
  • 332
  • 4
  • 21
  • Possible duplicate of [SecurityError: Blocked a frame with origin from accessing a cross-origin frame](http://stackoverflow.com/questions/25098021/securityerror-blocked-a-frame-with-origin-from-accessing-a-cross-origin-frame) – Mike Cluck Apr 25 '16 at 23:08

1 Answers1

2

You can't do this. Sorry.

The current location of an iframe, like all other properties of the child window, is only visible to the parent page if it's viewing a page on the same domain.

duskwuff -inactive-
  • 171,163
  • 27
  • 219
  • 269