Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use window.innerWidth to calcualte width #373

Closed
mbrevda opened this issue Jun 9, 2016 · 26 comments
Closed

use window.innerWidth to calcualte width #373

mbrevda opened this issue Jun 9, 2016 · 26 comments

Comments

@mbrevda
Copy link

mbrevda commented Jun 9, 2016

Im on a page where a parent has a min-width set which causes the iframe to size incorrectly. Is there any way to calculate the width based on window.innerWidth?

@davidjbradshaw
Copy link
Owner

Interesting idea.

@davidjbradshaw
Copy link
Owner

Welcome a PR if you have a moment to take a look and see if this works.

@mbrevda
Copy link
Author

mbrevda commented Jun 13, 2016

Would love to and might still, simply swamped atm. Was thinking of allowing a function as instead of one of the predefined string so that this is extendable to other use cases in the future.

Thoughts?

@davidjbradshaw
Copy link
Owner

I've thought about allowing a custom function to be written in the iFrame. This couldn't be passed from the parent, as that would be a major security problem.

@mbrevda
Copy link
Author

mbrevda commented Jun 13, 2016

Aren't the size options on the parent? I.e. isn't it the parents job to
determine the size the iframe should be?

On Mon, Jun 13, 2016, 8:26 PM David J. Bradshaw notifications@github.com
wrote:

I've thought about allowing a custom function to be written in the iFrame.
This couldn't be passed from the parent, as that would be a major security
problem.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#373 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAR4jFjeB3NkkxZwpcItmQPCLmR0YO00ks5qLZLPgaJpZM4IyHy3
.

@davidjbradshaw
Copy link
Owner

Yes, but their is an option in the iFrame to override this.

https://github.com/davidjbradshaw/iframe-resizer#heightcalculationmethod--widthcalculationmethod

Rather than pass a string, could make it an option to pass a function.

If you pass a function from the parent page, you create an attack vector for dodgy code.

@mbrevda
Copy link
Author

mbrevda commented Jun 13, 2016

Perhaps it should just be settable in the parent?

On Mon, Jun 13, 2016 at 10:38 PM David J. Bradshaw notifications@github.com
wrote:

Yes, but their is an option in the iFrame to override this.

https://github.com/davidjbradshaw/iframe-resizer#heightcalculationmethod--widthcalculationmethod

Rather than pass a string, could make it an option to pass a function.

If you pass a function from the parent page, you create an attack vector
for dodgy code.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#373 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAR4jD2pgREzYHlhL2VfcqVJXoR73lC3ks5qLbHCgaJpZM4IyHy3
.

@davidjbradshaw
Copy link
Owner

I had a thought about this and just added the ability to add custom sizing methods on the dev branch. This is really untested, and hopefully I will have some more time to write some tests and an example later this week, but in the meantime you should hopefully be able to do the following in the iFrame now.

<script>
    window.iFrameResizer = {
        widthCalcMethod: function() {
            return window.innerWidth;
        }
    }
</script>
<script src="js/iframeresizer.contentwindow.js"></script>

Oh and let me know if it really does work...

@mbrevda
Copy link
Author

mbrevda commented Jun 13, 2016

No, Im afraid it doesn't work No change in size detected

@davidjbradshaw
Copy link
Owner

Could post the log output?

@mbrevda
Copy link
Author

mbrevda commented Jun 13, 2016

[iFrameSizer][Host page: xxxxxx] [iFrame.onload] Sending msg to iframe[xxxxxx] (xxxxxx:8:false:true:32:true:true:null:bodyOffset:null:null:0:false:parent:scroll) targetOrigin: https://yyyyy.xxxxxx.net
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Initialising iFrame (https://yyyyy.xxxxxx.net/)
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] TargetOrigin for parent set to: *
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] HTML & body height set to "auto"
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Enable public methods
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Add event listener: Animation Start
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Add event listener: Animation Iteration
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Add event listener: Animation End
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Add event listener: Input
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Add event listener: Mouse Up
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Add event listener: Mouse Down
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Add event listener: Orientation Change
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Add event listener: Print
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Add event listener: Ready State Change
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Add event listener: Touch Start
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Add event listener: Touch End
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Add event listener: Touch Cancel
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Add event listener: Transition Start
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Add event listener: Transition Iteration
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Add event listener: Transition End
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Create body MutationObserver
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] In page linking not enabled
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event lock on
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Sending message to host page (xxxxxx:770:967:init)
host.js:1 [iFrameSizer][Host page: xxxxxx] Received: [iFrameSizer]xxxxxx:770:967:init
host.js:1 [iFrameSizer][Host page: xxxxxx] Checking connection is from: https://yyyyy.xxxxxx.net
host.js:1 [iFrameSizer][Host page: xxxxxx] Checking height is in range 0-Infinity
host.js:1 [iFrameSizer][Host page: xxxxxx] Checking width is in range 0-Infinity
host.js:1 [iFrameSizer][Host page: xxxxxx] IFrame (xxxxxx) height set to 770px
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event lock off
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] --
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event: mutationObserver: [object HTMLDivElement] attributes
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] No change in size detected
host.js:1 [iFrameSizer][Host page: xxxxxx] [Window resize] Sending msg to iframe[xxxxxx] (resize) targetOrigin: https://yyyyy.xxxxxx.net
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event: Parent window requested size check
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] No change in size detected
host.js:1 [iFrameSizer][Host page: xxxxxx] [Window resize] Sending msg to iframe[xxxxxx] (resize) targetOrigin: https://yyyyy.xxxxxx.net
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event: Parent window requested size check
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] No change in size detected
host.js:1 [iFrameSizer][Host page: xxxxxx] [Window resize] Sending msg to iframe[xxxxxx] (resize) targetOrigin: https://yyyyy.xxxxxx.net
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event: Parent window requested size check
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] No change in size detected
host.js:1 [iFrameSizer][Host page: xxxxxx] [Window resize] Sending msg to iframe[xxxxxx] (resize) targetOrigin: https://yyyyy.xxxxxx.net
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event: Parent window requested size check
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] No change in size detected
host.js:1 [iFrameSizer][Host page: xxxxxx] [Window resize] Sending msg to iframe[xxxxxx] (resize) targetOrigin: https://yyyyy.xxxxxx.net
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event: Parent window requested size check
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] No change in size detected
host.js:1 [iFrameSizer][Host page: xxxxxx] [Window resize] Sending msg to iframe[xxxxxx] (resize) targetOrigin: https://yyyyy.xxxxxx.net
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event: Parent window requested size check
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] No change in size detected
aggregated.js:1 The value "640px" for key "width" was truncated to its numeric prefix.
host.js:1 [iFrameSizer][Host page: xxxxxx] [Window resize] Sending msg to iframe[xxxxxx] (resize) targetOrigin: https://yyyyy.xxxxxx.net
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event: Parent window requested size check
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event lock on
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Sending message to host page (xxxxxx:883:640:resizeParent)
host.js:1 [iFrameSizer][Host page: xxxxxx] Received: [iFrameSizer]xxxxxx:883:640:resizeParent
host.js:1 [iFrameSizer][Host page: xxxxxx] Checking connection is from: https://yyyyy.xxxxxx.net
host.js:1 [iFrameSizer][Host page: xxxxxx] Checking height is in range 0-Infinity
host.js:1 [iFrameSizer][Host page: xxxxxx] Checking width is in range 0-Infinity
host.js:1 [iFrameSizer][Host page: xxxxxx] Requesting animation frame
host.js:1 [iFrameSizer][Host page: xxxxxx] IFrame (xxxxxx) height set to 883px
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event lock off
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] --
host.js:1 [iFrameSizer][Host page: xxxxxx] [Window resize] Sending msg to iframe[xxxxxx] (resize) targetOrigin: https://yyyyy.xxxxxx.net
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event: Parent window requested size check
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] No change in size detected
aggregated.js:1 The value "640px" for key "width" was truncated to its numeric prefix.
host.js:1 [iFrameSizer][Host page: xxxxxx] [Window resize] Sending msg to iframe[xxxxxx] (resize) targetOrigin: https://yyyyy.xxxxxx.net
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event: Parent window requested size check
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] No change in size detected
aggregated.js:1 The value "640px" for key "width" was truncated to its numeric prefix.
host.js:1 [iFrameSizer][Host page: xxxxxx] [Window resize] Sending msg to iframe[xxxxxx] (resize) targetOrigin: https://yyyyy.xxxxxx.net
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event: Parent window requested size check
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] No change in size detected
host.js:1 [iFrameSizer][Host page: xxxxxx] [Window resize] Sending msg to iframe[xxxxxx] (resize) targetOrigin: https://yyyyy.xxxxxx.net
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event: Parent window requested size check
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event lock on
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Sending message to host page (xxxxxx:770:1088:resizeParent)
host.js:1 [iFrameSizer][Host page: xxxxxx] Received: [iFrameSizer]xxxxxx:770:1088:resizeParent
host.js:1 [iFrameSizer][Host page: xxxxxx] Checking connection is from: https://yyyyy.xxxxxx.net
host.js:1 [iFrameSizer][Host page: xxxxxx] Checking height is in range 0-Infinity
host.js:1 [iFrameSizer][Host page: xxxxxx] Checking width is in range 0-Infinity
host.js:1 [iFrameSizer][Host page: xxxxxx] Requesting animation frame
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event lock off
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] --
host.js:1 [iFrameSizer][Host page: xxxxxx] IFrame (xxxxxx) height set to 770px
host.js:1 [iFrameSizer][Host page: xxxxxx] [Window resize] Sending msg to iframe[xxxxxx] (resize) targetOrigin: https://yyyyy.xxxxxx.net
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event: Parent window requested size check
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] No change in size detected
host.js:1 [iFrameSizer][Host page: xxxxxx] [Window resize] Sending msg to iframe[xxxxxx] (resize) targetOrigin: https://yyyyy.xxxxxx.net
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event: Parent window requested size check
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] No change in size detected
host.js:1 [iFrameSizer][Host page: xxxxxx] [Tab Visable] Sending msg to iframe[xxxxxx] (resize) targetOrigin: https://yyyyy.xxxxxx.net
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] Trigger event: Parent window requested size check
app-f720aa844c.js:8 [iFrameSizer][xxxxxx] No change in size detected

Also tried as non global. I could send you a link, offline, if you'd like.

@davidjbradshaw
Copy link
Owner

Are you setting sizeWidth to true and sizeHeight to false to make it calc the width?

Also can you add a console.log to the custom sizing method so we're sure it's running.

@mbrevda
Copy link
Author

mbrevda commented Jun 13, 2016

tried console.log, got nothing. Not setting that stuff. Should I be?

davidjbradshaw added a commit that referenced this issue Jun 13, 2016
@davidjbradshaw
Copy link
Owner

Yep, otherwise it only calcs the height.

@mbrevda
Copy link
Author

mbrevda commented Jun 13, 2016

hmm... perhaps that was my issue to begin with?

@mbrevda
Copy link
Author

mbrevda commented Jun 13, 2016

this is what I;m using, still not resizing properly;

{log:true, sizeWidth:true, sizeHeight:false, widthCalcMethod: () => window.innerWidth}

@davidjbradshaw
Copy link
Owner

WidthCalcMethod can only be set in the iFrame. See above.

@mbrevda
Copy link
Author

mbrevda commented Jun 13, 2016

Im a bit confused. This seemed to imply that the options needs to be set on the parent site?

@mbrevda
Copy link
Author

mbrevda commented Jun 13, 2016

I think I get it, but - shouldnt the iframe resize based on the parent window size? Why would it do its on detection?

@davidjbradshaw
Copy link
Owner

It's not possible to pass a function from the parent to the iFrame via postMessge

@mbrevda
Copy link
Author

mbrevda commented Jun 13, 2016

But why would you? Just figure out the width on the parent, and pass the width to the child? Sorry if im being dumb here, just trying to understand

@davidjbradshaw
Copy link
Owner

The parent window resizing triggers a message to be sent to the iFrame to ask it to work out it's new size. The iFrame then works out it's new size and sends a message back to the parent, which then update the iFrame to the new size.

@davidjbradshaw
Copy link
Owner

Content in the iFrame changing also triggers a size update

@mbrevda
Copy link
Author

mbrevda commented Jun 13, 2016

I see. In that case, perhaps my approach in resolving my issue (i.e. that the iframe container has a min-width) is flawed?

@davidjbradshaw
Copy link
Owner

Not sure what the problem is your trying to solve is. Their is an option to set min and max sizes.

@mbrevda
Copy link
Author

mbrevda commented Jun 13, 2016

Ive been barking up the wrong tree. Closing. Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants