troubleshooting Question

Exception reading an iframe content from chrome console

Avatar of Rohit Bajaj
Rohit BajajFlag for India asked on
JavaScriptWeb ApplicationsWeb BrowsersJava EE
12 Comments1 Solution5888 ViewsLast Modified:
Hi,
I have a following html page  :
<!DOCTYPE html>
<html>
  <head>
    <title>${note.title}</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">

    <script>var mode = "${mode}"</script>
    <script>var require = {config: function (c) {require = c}}</script>
    <script src="${resourcePrefix}/js/config.js"></script>
    <script data-main="${resourcePrefix}/js/view.js" src="${resourcePrefix}/lib/require.js"></script>
    <link media="screen and (min-device-width: 737px)" rel="stylesheet" href="${resourcePrefix}/css/view.css"/>
    <link media="only screen and (min-device-width: 320px) and (max-device-width: 736px)" rel="stylesheet" href="${resourcePrefix}/css/view-mobile.css" />
  </head>

  <body>
    <h1 id="title">${note.title}</h1>
    <div id="textContainer">
    <iframe id="iframe" scrolling="yes" frameborder="0" style="position: relative; height: 100%; width: 100%;" src="${dataUri}">
    </iframe>
    </div>
    <div id="buttons">
        <button id="edit">Edit Note</button>
    </div>
    <div class="invisible" data-edit-url="${editURL}">
    </div>
  </body>
</html>

This page is a jsp which is returned from server running at my local machine.
However if i type the following command in console : $('iframe').contents() i get the following error :
Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://localhost:8080" from accessing a cross-origin frame.(…)n.each.contents @ jquery-2.1.4.min.js:2n.extend.map @ jquery-2.1.4.min.js:2n.fn.(anonymous function) @ jquery-2.1.4.min.js:2(anonymous function) @ VM449:2InjectedScript._evaluateOn @ VM302:875InjectedScript._evaluateAndWrap @ VM302:808InjectedScript.evaluate @ VM302:664

Which is strange as the iframe is loaded from my local server its not loaded from some other domain...
Also the same thing works fine on firefox.. Its only causing problems in chrome .

How can i get rid of this ?
Thanks
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros