0

I found a line of code here: parent.document.body.clientWidth How can I get a parent window's height from within iFrame using jQuery? that i use to find the width of the parent page from an iframe.

It works in Edge, IE 11, Firefox but not for Chrome or Opera.

Is there a fix or perhaps a different solution to the problem?

Example

IFrame

html

<body onresize="bodyRePr()">
    <script src="examplescript.js"></script>
    [...]
</body>

js

function bodyRePr(){
    if (parent.document.body.clientWidth > 720){
        document.getElementById("example").style.width = "460px";
    }
    else{
        document.getElementById("example").style.width = "100%";
    }
}

I see this error when opening the page in Opera, not sure what it means. enter image description here

requested:

html is of another page including the iframe

<body onscroll="toggleMenu()" onload="startup()" onload="getBrowserInfo()" onresize="bodyRe()">
    [...]
    <nav id="profileMenu">
        <iframe id="profileMenuIframe"></iframe>
        <div onclick="closeProfileMenu()" class="closeBtn">&#9587;</div>
    </nav>
[...]
</body>

css

#profileMenu{
    z-index: 6;
    position: fixed; top: 0; left: 0;
    width: 500px; height: 100%;
    margin-left: -100%;
    background: rgb(30,30,30);
    transition: margin-left 0.2s;
}
#profileMenuIframe{
    width: 500px;
}
Community
  • 1
  • 1

1 Answers1

0

You can't test frame/parent references offline in Chrome, using file:// URL's as shown in your example.

And you can't reference your online resources either, while testing offline, because that would be cross-site scripting.

To test your parent frame references, you either need to use a browser that supports offline URL's the same way it supports online URL's, or test both parent and frames using an HTTP server.

david
  • 2,017
  • 17
  • 26