【问题标题】:Close dialog and redirect if url present如果 url 存在,则关闭对话框并重定向
【发布时间】:2012-06-18 16:29:13
【问题描述】:

我在链接中添加了一个 css 类,单击该类时会关闭 jquery ui 对话框,但我希望它重定向到页面(在 iframe 中)并关闭对话框。

目前,如果链接具有 href 值,它只会重定向而不关闭对话框。如果没有 href 值,它会根据需要关闭对话框。

<a href="http://...." class="button hide" target="contentFrame">Some Text</a>


$(".hide").bind("click", function(){
  $(".dialog").dialog('close');
});

所以我需要先以某种方式关闭对话框,然后再进行重定向。

我可以覆盖点击并以某种方式做到这一点吗? 如果没有 href 值,或者它为空,我不需要重定向,只需关闭对话框即可。

【问题讨论】:

  • 您是否正在从对话框按钮处理程序执行重定向?

标签: jquery jquery-ui dialog


【解决方案1】:

关闭对话框后需要手动重定向(这样可以控制顺序)。大致如下:

$(".hide").bind("click", function(e){
  e.preventDefault();
  $(".dialog").dialog('close');
  $iframe.attr('src',$(this).attr('href'));
})

请记住,您必须preventDefault() 否则链接会像往常一样点击。有关示例和更多信息,请参阅jQuery docs

【讨论】:

【解决方案2】:

试试这个:

$(".hide").bind("click", function(event){
  event.preventDefault();
  $(".dialog").dialog('close');
  window.location.href = $(this).attr('href');
})

【讨论】:

    【解决方案3】:

    你可以使用

    window.location = "http://www.google.com/"
    

    重定向。把它放在你的对话框关闭行之后。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-14
      • 1970-01-01
      • 2018-11-27
      • 2020-08-11
      • 2012-08-11
      相关资源
      最近更新 更多