0

我在花哨的框中有一个登录页面,单击登录时我希望在新选项卡中打开安全页面并使用此代码

// 在 btnlogin_click 的代码上

FormsAuthentication.RedirectFromLoginPage(loginID, false);
   string redirectTo = GetResPath("/webPages/Default.aspx");
                ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "add2", "parent.jQuery.redirTo='" + redirectTo + "'; parent.jQuery.fancybox.close();", true);

//在aspx页面上

 <script type="text/javascript">
    $(document).ready(function () {
        $('[id*=logn_btn_new]').fancybox({
            'width': 480,
            'height': 280,
            'padding': 10,
            'margin': 10,
            'hideOnOverlayClick': false,
            'scrolling': 'no',
            'autoScale': false,
            'transitionIn': 'none',
            'transitionOut': 'none',
            'type': 'iframe',
            'onClosed': function () {
                try {

                    if ($.redirTo != null && $.redirTo.length > 0) {
                        var pop = window.open($.redirTo, '_newtab');

                        if (pop == null) {
                            alert("Please allow popups.");
                        }


                    }
                }
                catch (err) {
                    alert(err);
                }
            }
        });
    });
</script>

并且 redirTo 是隐藏字段。

我无法在新标签中打开页面有人可以帮忙吗?

4

1 回答 1

2

这是一个困难的问题,因为它是由用户的网络浏览器设置控制的。

您使用的方法特定于 FireFox,并且确实会打开一个新选项卡。但这仍然可以被用户的设置覆盖。

然而,为了在其他浏览器中获得相同的效果,这里有一篇关于 IE 的文章Open a new tab in IE through Javascript

值得考虑为什么需要这样做。如果您在未通知用户的情况下打开新选项卡/窗口,用户可能会感到困惑。是否可以不打开新窗口并将所有内容保留在同一页面中?然后你知道人们在逻辑上会在一定程度上得到相同的结果。

我希望这有帮助!

于 2012-05-08T11:39:06.667 回答