Attaching a function to the parent window from an iframe and getting proper scope?

Try this: var p$ = parent.window. $; parent.window. ShowPreview = function(coords) { if (parseInt(coords.

W) > 0) { var rx = 200 / coords. W; var ry = 250 / coords. H; p$('#preview').

Css({ width: Math. Round(rx * 400) + 'px', height: Math. Round(ry * 533) + 'px', marginLeft: '-' + Math.

Round(rx * coords. X) + 'px', marginTop: '-' + Math. Round(ry * coords.

Y) + 'px' }); } } If you're making a function for the parent window, you probably want it to use the parent window's jQuery instead of the child window's. You'll also need to make sure the parent page has its own copy of jQuery. (If it doesn't, and you're brave, you could try dynamically giving it one!) edit Here's how you could do it with a closure instead of the global p$: parent.window.

ShowPreview = (function(p$) { return function(coords) { // ... same as above }; })(parent.window. $).

I tried this, it doesn't seem to be working. P$ is not defined. – Ronald Apr 11 '10 at 21:01 Well does your parent page have a tag to import jQuery?

It should. – Pointy Apr 11 '10 at 21:02 Yep. It does.

I can call it successfully too, like so: parent. $("#crop-controls"). Html(cropcontrols); It's just this function that is having the scoping issue.

:\ – Ronald Apr 11 '10 at 21:04 Well if "parent.window. $" is defined, then how can "p$" not be defined? You could do the definition with a closure I guess.

– Pointy Apr 11 '10 at 21:08 Well, I tried the same code in Chrome and it works there. So this looks like a Firefox issue.. hmm... – Ronald Apr 11 '10 at 21:11.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions