【问题标题】:Change window.location.href upon dismissal of modal解除模式后更改 window.location.href
【发布时间】:2017-01-11 16:35:11
【问题描述】:

按照 OctoberCMS 指南,当用户尝试到达特定路径(例如:www.foo.com/bar)时,我需要将用户重定向到带有 php 变量的主页(例如:www.foo.com/?bar=1 ) 并在找到变量时打开模式。

我创建了 bar.htm,它使用正确的变量重定向:

title = "bar"
url = "/bar"
layout = "default"
meta_title = ""
meta_description = ""
is_hidden = 0
==
<?php
function onStart() {
  header('Location:/?bar=1');
}
?>
==

然后在我的 JS 中(#submitBtn 是发送表单的模态按钮)

$(document).ready(function(){
  if(window.location.href.indexOf('1') > -1) {
      $('#myModal').modal('show');
      $('#submitBtn').click(function() {
        window.location.href='/';
    })
  } 
});

所以这是行不通的,它只是在一个恒定循环中显示模态,并且永远不会移动到成功模态或更改 href。此表格在所有其他情况下都可以正常工作,因此我认为问题不存在。

缩短示例模式代码:

$('#myModal').on('show.bs.modal', function (event) {
    var newForm = $('#newFakeForm');
    var config = {
      submitBtn: $('#submitBtn'),
      contactModal: $('#myModal'),
      successModal: $('#successModal'),
    };

    initContactForm(newFakeForm, config);

    });

和我的 HTML 按钮来关闭模式:

谢谢

【问题讨论】:

    标签: javascript php jquery modal-dialog octobercms


    【解决方案1】:

    如果你在 JS 上做重定向呢? 只需监听 hidden.bs.modal 事件并在那里进行重定向。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多