0

I need some help for href link open to new tab in jquery. I getting the following resuts for, if am click following link Pay now i get the results from RtObject.ReturnVal.my results success get the following results displayed in new tab. $(function () { $("#OrderTable > tbody > tr > td> .paynow").click('click', function (Myevent) {

            Myevent.preventDefault();

            var passval = $(this).parents().siblings('td:eq(1)').text();

            $.ajax({
                type: "POST",
                datatype: "json",
                async: true,
                url: '/MyAccount/PayNow?OrderId=' + passval,
                contentType: "application/json; charset=utf-8",
                success: function (RtObject) {
                    //alert(RtObject.isError);
                    //alert(RtObject.CId);
                    if (!RtObject.isError) {
                        //alert(RtObject.isError);
                        if (RtObject.CId == 1) {
                            var newwin;
                            if (newwin && !newwin.closed) {
                                newwin.focus();

                            } else {


                                $(this).target = "_blank";

                                window.location = RtObject.ReturnVal;


                            }
                        }
                        else if (RtObject.CId == -1) {
                            jAlert(RtObject.Message, "Failure");
                        }
                    }
                },
                failure: function (response) {
                    jAlert("Cant go to payment process", "Failure");
                }
            });

        });

please help me to solve this.

tereško
  • 58,060
  • 25
  • 98
  • 150
White
  • 31
  • 1
  • 7
  • Possible duplicate of [jQuery: go to URL with target="\_blank"](http://stackoverflow.com/questions/6673473/jquery-go-to-url-with-target-blank) – Arumuga Raja Mar 29 '16 at 08:35

1 Answers1

0

Instead window.location = RtObject.ReturnVal; use window.open(RtObject.ReturnVal, '_blank');

  • Hi Viktor, I used that code also but its asking for popup Blocked. i need open new tab without asking for popup blocked. – White Mar 29 '16 at 08:31
  • @White then you'll use this function `function openInNewTab(link) { var element = document.createElement('a'); element.target = '_blank'; element.style.display = 'none'; element.href = link; element.className += 'linkOnNewTab'; element.click(); }` for example `openInNewTab(RtObject.ReturnVal);` instead `window.location = RtObject.ReturnVal;` – Viktor Kondolovskiy Mar 29 '16 at 08:57
  • Hi, var element = document.createElement('a'); element.target = '_blank'; element.style.display = 'none'; element.href = RtObject.ReturnVal; element.className += RtObject.ReturnVal; element.click(); but again asking for popup blocked. – White Mar 29 '16 at 09:01
  • Pay now if we are click pay now button. its open new tab. – White Mar 29 '16 at 09:17