关闭Fancybox 2窗口并重定向父窗口 [英] Close Fancybox 2 window and redirect parent window

查看:189
本文介绍了关闭Fancybox 2窗口并重定向父窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Fancybox 2 iframe模式窗口,其中包含添加到购物车"表单.提交表单后,将在Fancybox模式窗口中加载成功/确认页面.

I've got a Fancybox 2 iframe modal window that contains an 'Add to Cart' form. When the form is submitted, a success/confirmation page will be loaded within the Fancybox modal window.

我想在此成功/确认页面上运行一个脚本,该脚本关闭Fancybox窗口并将父窗口重定向到以下URL:'/shop/basket'我该怎么做?

I want to run a script on this success/confirmation page that closes the Fancybox window and redirects the parent window to this URL: '/shop/basket' How can I do this?

这是我目前获得的代码(它仅关闭Fancybox窗口,但不执行父窗口重定向):

Here's the code I've got at the moment (which just closes the Fancybox window, but doesn't do the parent window redirect):

<script type="text/javascript">
  $(function() { parent.$.fancybox.close(); });
</script>

这是我如何在我的functions.js文件中初始化Fancybox的方法:

This is how I initialise the Fancybox within my functions.js file:

$(".add-to-cart-popup").fancybox({
    width       : 580,
    height      : 744,
    closeClick  : false,
    scrolling   : 'auto'
});

这段代码可以满足我的需求-但是有人可以想到实现此目的的更好方法吗?这只是我一起破解的东西:

This code does what I'm looking for - but can anyone think of any better ways of doing this? This is just something I've hacked together:

<script type="text/javascript">
  $(function() { parent.$.fancybox.close(); });
  window.parent.location.href = '/shop/basket';
</script>

推荐答案

不要尝试从子页面进行重定向,而是尝试从父页面本身进行重定向.

Don't try the redirect from the child page, but from the parent page itself.

如果您的父页面(functions.js)中包含以下代码:

If you have this code in your parent page (functions.js) :

$(".add-to-cart-popup").fancybox({
    width       : 580,
    height      : 744,
    closeClick  : false,
    scrolling   : 'auto'
});

然后只需向其中添加afterClose回调;

Then just add the afterClose callback to it like ;

$(".add-to-cart-popup").fancybox({
    width       : 580,
    height      : 744,
    closeClick  : false,
    scrolling   : 'auto',
    afterClose  : function() {
       location.href = "/shop/basket";
    }
});

...您仍然需要在子页面上执行parent.$.fancybox.close();

... you still need to perform parent.$.fancybox.close(); from the child page

这篇关于关闭Fancybox 2窗口并重定向父窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆