javascript - Setting global variable across fancebox iframe -


this question has answer here:

i have webpage , calling fancybox plugin iframe show page. have used page upload image. now, want pass image path parent page after fancybox closes.

i thought of setting global variable on parent page, , set value of variable inside fancybox iframe (to uploaded image path). on parent page placed afterclose() fancybox read variable's value. work? if not, else can try?

parent file code:

var globalimageurl = ""; $('.fancybox').fancybox({         maxwidth    : 800,         maxheight   : 600,         fittoview   : false,         width       : '70%',         height      : '70%',         autosize    : false,         closeclick  : false,         openeffect  : 'none',         closeeffect : 'none',          afterclose: function(){             alert(globalimageurl);         }     }); 

iframe code:

<?php if(strlen($photo_exists)>0){      echo "<script>globalimageurl = 'imagepath';</script>"; } ?> 

thanks.

firstly document.domain of parent , iframe must same iframe access parent variables.

secondly code should this:-

<?php if(strlen($photo_exists)>0){      echo "<script>if(top.globalimageurl) top.globalimaeuirl='imagepath';</script>"; } ?> 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -