关闭fancybox时,将变量从fancybox传递到父页面 [英] Passing variable from fancybox to parent page when closing fancybox
问题描述
你好我试图发送一个变量从一个孩子iframe fancybox到父母。但我似乎无法掌握如何去做。有没有人有一个想法。我已经用js尝试过了。一位朋友建议使用php来做,但没有找到解决方案。我现在有一个混乱。我尝试了另一个类似于我的问题的答案,但没有运气。这里是代码
这是在fancybox中:
< script type =text / javascript>
函数OnClickButton(nombre){
parent。$。nombre(nombre);
parent。$。fancybox.close();
}
< / script>
<?php foreach($ files1 as $ file):?>
<?php if($ cont> 1){?>
< li>
< a onclick =OnClickButton('<?php echo $ file;?>'); href =<?php echo $ file;?>>< img style =width:50px;
src =img / folderImg.png>< / a>
< / li>
<?php}?>
<?php $ cont ++; endforeach?>
这在父页面中
function nombre(nombre){
name = nombre;
alert(nombre)
}
$(document).ready(function(){
$(。fancybox)。fancybox();
});
$(document).ready(function(){
$(。various)。fancybox({
maxWidth:800,
maxHeight:400,
fitToView:false,
width:'70%',
height:'70%',
autoSize:false,
closeClick:false,
openEffect:'none ',
closeEffect:'none',
afterClose:function(){
if(name =='folder 1'){
$('。fancybox ('。bumb')。fancybox()。trigger('click');
}
if(name =='folder 2'){
$('。fancybox-thumb2')。 fancybox()。trigger('click');
}
if(name =='folder 3'){
$('。fancybox-thumb3')。fancybox()。trigger ('click');
}
}
});
});
我会尝试两种解决方案,我不知道如果在你的情况下可以工作,但非常稳固。
1)sessionstorage:
使用sessionstorage和jquery你可以保存一个参数并稍后在任何页面中使用它。
sessionStorage.setItem(nameofthestorage,yourvalue);
并取得储存的资讯
var x = sessionStorage.getItem(nameofthestorage);
2)保存php会话:
我有点生锈的PHP,但你可以看到这个官方和简单的指导
http ://www.w3schools.com/php/php_sessions.asp
Hi im trying to send a variable from a child iframe fancybox to the parent. But i cant seem to grasp how to do it. Does anyone have a idea. I already tried with js. A friend suggested to do it with php but havent find a solution. I have a mess right now. I tried another questions answers similar to mine with no luck. Here is the code this is in the fancybox:
<script type="text/javascript">
function OnClickButton (nombre) {
parent.$.nombre(nombre);
parent.$.fancybox.close();
}
</script>
<?php foreach($files1 as $file): ?>
<?php if ($cont>1) { ?>
<li>
<a onclick="OnClickButton ('<?php echo $file;?>');" href="<?php echo $file;?>"><img style="width: 50px;"
src="img/folderImg.png"></a>
</li>
<?php } ?>
<?php $cont++; endforeach ?>
This is in the parent page
function nombre (nombre) {
name = nombre;
alert(nombre)
}
$(document).ready(function() {
$(".fancybox").fancybox();
});
$(document).ready(function() {
$(".various").fancybox({
maxWidth : 800,
maxHeight : 400,
fitToView : false,
width : '70%',
height : '70%',
autoSize : false,
closeClick : false,
openEffect : 'none',
closeEffect : 'none',
afterClose : function() {
if (name == 'folder 1') {
$('.fancybox-thumb').fancybox().trigger('click');
}
if (name == 'folder 2') {
$('.fancybox-thumb2').fancybox().trigger('click');
}
if (name == 'folder 3') {
$('.fancybox-thumb3').fancybox().trigger('click');
}
}
});
});
I will try two solution, i don't know if in your case can works but are pretty solid.
1) sessionstorage:
using sessionstorage with jquery you can save a parameter and use it later in any page.
sessionStorage.setItem("nameofthestorage", yourvalue);
and to take the saved info
var x = sessionStorage.getItem("nameofthestorage");
2)save a php session:
i'm a bit rusted with php but you can see this official and easy guide http://www.w3schools.com/php/php_sessions.asp
这篇关于关闭fancybox时,将变量从fancybox传递到父页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!