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
Post a Comment