我在fancybox iframe 中使用登录表单标签。
对于我的返回参数,我使用的是<?php echo $_SERVER['HTTP_REFERER']; ?>
,以便将用户带回到他们从哪个页面开始。不幸的是,它会将他们带回到 iframe 中的那个页面。
如何target="_top"
向返回链接或其他将关闭 iframe 并在父窗口中管理重定向的 jQuery 调用添加属性?
谢谢,
泰
我在fancybox iframe 中使用登录表单标签。
对于我的返回参数,我使用的是<?php echo $_SERVER['HTTP_REFERER']; ?>
,以便将用户带回到他们从哪个页面开始。不幸的是,它会将他们带回到 iframe 中的那个页面。
如何target="_top"
向返回链接或其他将关闭 iframe 并在父窗口中管理重定向的 jQuery 调用添加属性?
谢谢,
泰
在我看来,您可能想返回一个执行以下操作的插页式页面:
$.fancybox.close()
){redirect='{segment_2}'}
)重定向到所需的页面FWIW,-s。
使用这个免费的附加组件http://devot-ee.com/add-ons/page-history来获取访问的最后一页(或前一页到最后一页),而不是使用 HTTP_REFERER。
要么设置为表单的一部分(RET 的隐藏字段),要么输出到控制表单提交的 JavaScript(或表单提交到的页面。
<input type="hidden" value="{exp:page_history:get page=‘1’}" name="RET"/>
您可以在结果页面上有一些 Jquery 重定向到同一页面,但不在 iFrame 内:
if (top.location.href != document.location.href) {
//### Inside an iFrame ###
if (document.location.href.indexOf("/redirected page after login") >= 0) {
//### Breakout of iFrame ###
$("body").css("display","none"); //Hide to minimise 'flicker'
top.location.href = document.location.href;
}
}
或者让一些 JavaScript 捕获登录表单提交,然后通过 Ajax 提交页面,然后重定向到所选的 URL(您不需要关闭 fancybox,只需 target top.location.href
.
这是通过 Ajax 发送带有服务器错误检查响应的登录表单的示例 JQuery:
//### LOGIN FORM SUBMISSION ###
function SubmitLogin() {
//### Send form via AJAX ###
$.ajax({
type: "POST",
data: $("#login-form").serialize() + "&action=" + $("#login-form").attr("action"),
dataType: "html",
success: function (html) {
//### Successfully received an html page from the server ###
if ( html.search(/error/i) >= 0 ) {
if (html.search(/username you submitted was not found/i) >= 0) {
$("#login-username").addClass('error');
$("#login-username").after('<label class="error" for="login-username" generated="true">Email address doesn\'t exist<br />Re-check or register an account</label>');
} else if (html.toLowerCase().indexOf("account does not exist") != -1) {
//Do appropriate selection & error message
} else if (html.search(/You did not submit a valid email address/i) >= 0) {
//Do appropriate selection & error message
} else if (html.search(/captcha/i) >= 0) {
$("#captcha").addClass('error').after('<label class="error" generated="true">' + $("#captcha").attr('title') + '</label>')
} else if (html.search(/password/i) >= 0) {
$("#login-password").addClass('error');
$("#login-password").after('<label class="error" for="login-username" generated="true">You have entered an incorrect password</label>');
} else if (html.search(/already logged in/i) >= 0) {
$("#login-butn").after('<label class="error" for="login-username" generated="true">User already logged in!</label>');
} else if (html.search(/account has not been activated yet/i) >= 0) {
$("#login-butn").after('<label class="error" for="login-username" generated="true">Account has not been activated yet<br />Check your email and activate</label>');
} else {
}
} else {
//### Successfully Logged in ###
top.location.href = "where ever you want to go";
// Target RET field of form here...?
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
//### Error occurred, could be server, CMS or 404 ###
}
});
} //### End of SubmitLogin function ###
这只是一个基于一些 EE1 错误消息的示例,我已经用来自 EE2 的几个错误消息进行了更新,所以如果您选择沿着 Ajax 提交路径并因此重定向,应该给您一个开始。
我的建议是不要在您的 FancyBox 中使用 iframe,而只是在您的页面上使用一个隐藏的片段,其中包含您的登录表单。这样您就不必修改任何内容,因为登录表单将始终加载在当前页面上。
只需从模板中的#pageheader
div开始的所有内容login_form
,将其#login
放在全局模板中某处(页眉、页脚、任何位置)的 div 中,然后使用一些 javascript(或者,如果您愿意,使用 CSS)将其隐藏。然后只需链接到“#login”而不是“/home/login_form”。
您可以type: 'iframe'
从您的 FancyBox jQuery 调用中删除参数 - FancyBox 足够聪明,可以根据链接确定它正在加载的内容(在这样的片段链接的情况下,它会将自身设置为“内联”模式)。
如果登录表单在全局嵌入中,您可以仅在该嵌入中启用 PHP。或者,如果您使用的是代码片段,请改用Current 插件,这样您就不必在所有模板中启用 PHP。
解决方案是不使用 EE 登录表单标签,而是对表单进行硬编码。这允许添加一个目标属性:
<form method="post" action="http://domain.com/" target="_top" >
<div class='hiddenFields'>
<input type="hidden" name="XID" value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" />
<input type="hidden" name="ACT" value="12" />
<input type="hidden" name="RET" value="<?php echo $_SERVER['HTTP_REFERER']; ?>" />
<input type="hidden" name="site_id" value="1" />
</div>
谢谢您的帮助。
泰