【问题标题】:location.href not redirecting to https:// urlslocation.href 未重定向到 https:// 网址
【发布时间】:2013-08-01 21:40:58
【问题描述】:

一直在表单的Thankyou页面上使用以下内容在 5 秒内重定向回表单,并用值巧妙地预先填写名称字段:

<script> setTimeout(function() {location.href = '<?php echo $var3['returnurl']  ?>?fullName[first]=<?php echo $var1['first'] ?>&fullName[last]=<?php echo $var2['last']  ?>'}, 5000); </script>

在 returnurl 字段是 https:// url 之前效果很好。 然后它会停留在thankyou页面上,循环尝试进行重定向。 没有涉及 iframe .... 尝试过 top.location.href ...不好...甚至尝试过 location.replace

任何人都可以看到可能影响重定向到 https:// url 的代码的任何限制。

php 文件中的代码...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=no"> 
  <meta name="HandheldFriendly" content="True">
  <meta name="MobileOptimized" content="width">

    <title>Thankyou</title>

    <style type="text/css">

body 
{
margin: 0px;
padding: 0px;
background: #fff;
font-family: Arial;
}

#message
{
position: absolute;
left: 50%;
width: 320px;
margin-left: -160px;
}

</style>

<?php
$answers = $_POST;
$var1 = array("first" => $answers[fullname][0]);
$var2 = array("last" => $answers[fullname][1]);
$var3 = array("returnurl" => $answers[returnurl]);
 ?> 

</head>

<body>

<script>
  setTimeout(function() {location.href = '<?php echo $var3['returnurl']  ?>?fullName[first]=<?php echo $var1['first'] ?>&fullName[last]=<?php echo $var2['last']  ?>'}, 5000); // this duration is in millisecs
</script>

<div id="message">

<p>&nbsp;</p>
<div style="text-align: center;"><h1>Thank You!</h1></div>
<div style="text-align: center;">Your submission has been received.</div>
<div style="text-align: center;">We're most grateful</div>
<div style="text-align: center;">&nbsp;</div>
<div style="text-align: center;"><img src="http://www.mazeguy.net/bigsmilies/thumbsup.gif"></img></div>
<div style="text-align: center;">&nbsp;</div>
<div style="text-align: center;">You will return in 5 seconds</div><br />

</body>
</html>

这是提交的结果...Thankyou 页面源显示...是的,安全页面 url 没有通过 ....

<script>
setTimeout(function() {location.href = '?fullName[first]=&fullName[last]='}, 5000); //     this duration is in millisecs
</script>

【问题讨论】:

  • 请向我们展示呈现的 HTML。
  • 脚本实际上是这样嵌入页面的还是只是为了我们的可读性?我的意思是它是否像
  • @Rooster 这很可能是内联在他的 .php 文件中。
  • @Mark $var3['returnurl'] 的值是多少?
  • 查看页面的view-source:,看看生成了什么代码

标签: php javascript


【解决方案1】:

您是否考虑过通过 Ajax 提交表单?用户永远不会离开表单提交页面。您可以简单地显示带有确认消息的模式。这似乎比重定向用户更简单。这也可能是更好的用户体验。

假设您的表单有一个“提交”类的提交按钮。你可以在 jQuery 中做这样的事情:

$(function() {
    $('body').on('click', '.submit', function(event) {
        event.preventDefault();
        var target = event.currenTarget;
        var form = $(target).closest('form');
        var action = $(form).attr('action');
        $.post(action, form.serialize())
            .done(function() {
                alert('Thanks for your submission!');
            })
            .fail(function() {
                alert('Oops! Something went wrong... PLease try again.');
            });
    });   
});

查看 Bootstrap JS。他们有一些你可以使用的漂亮的模态。

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-09
    • 1970-01-01
    • 2021-04-02
    • 2014-10-21
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    • 2021-10-21
    相关资源
    最近更新 更多