G.S Bhangal
G.S Bhangal

Reputation: 3280

open in new tab of browser programmatically

i have a login page in fancy box and on click of login i want the secure pages open in the new tab and uses this code

// on code at 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);

//on aspx page

 <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>

and redirTo is hidden fielld.

i am not able to open page in new tab can anybody help?

Upvotes: 0

Views: 1385

Answers (1)

Nabster
Nabster

Reputation: 93

This is a difficult one, as it is something that is controlled by the user's web browser settings.

The method that you are using is specific to FireFox and will indeed open a new tab. But this can still be overridden by the user's settings.

However to get the same effect in other browsers here is an article for IE Open a new tab in IE through Javascript

It is worth considering why you need to do this. Users may be confused if you open a new tab / window without informing them. Is it possible to not open a new window and keep everything in the same page? Then you know that people logically will have the same results to an extent.

I hope this helps!

Upvotes: 2

Related Questions