1

This is my ajax request

 $.ajax({
        type: "POST",
        url: "Performance.aspx/GenerateMatrix",
        data: '{OrgId: ' + $('#hidOrgId').val() + ',SurveyFormId: ' + $('#divMatrixInfo .FeedbackForm').val() + ',GoalId: ' + $('#divMatrixInfo .FeedbackGoal').val() + ',StartDate: ' + "'" + StartDateTime + "'" + ',EndDate: ' + "'" + EndDateTime + "'" + ',EmployeeId: ' + "'" + $('#divMatrixInfo .FeedbackEmployee').val() + "'" + ',QuestionId: ' + "'" + $('#divMatrixInfo .FeedbackQuestion').val() + "'" + '}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
                        CloseModelOverLay('divMatrixInfo');
                        window.open('GenerateMatrix.aspx', '_blank');
                        $('#ddlPDPView').val('Goals');
                        $('#ddlPDPView').change();
        },
        failure: function (response) {
                        alert(response.d);
        }
      });

I want to open GenerateMatrix.aspx to open in new tab by this

window.open('GenerateMatrix.aspx', '_blank');

but instead it opens in new pop up window.

halfer
  • 19,824
  • 17
  • 99
  • 186
rahul
  • 7,573
  • 7
  • 39
  • 53
  • 2
    Are you sure you're doing it right, and that the browser supports it etc. Try this [FIDDLE](http://jsfiddle.net/6Wfku/), does that work as expected ? – adeneo Sep 25 '12 at 04:43
  • 1
    duplicate question http://stackoverflow.com/questions/726761/javascript-open-in-a-new-window-not-tab – Neverever Sep 25 '12 at 04:44
  • Sorry, you can't control whether the browser opens up a new window or tab when you use `window.open` - it's whatever the user has set in their browser settings. But what I have noticed is that if you specify the third parameter for `window.open`, the "options" parameter, and set the width/height, it opens in a new window...not sure how cross browser compatible that is though. – Ian Sep 25 '12 at 04:45
  • And what is the `failure` option for jQuery `$.ajax`? Are you sure you don't mean `error`? – Ian Sep 25 '12 at 04:46
  • @adeneo this work fine on ie and firefox only problem is with chrome – rahul Sep 25 '12 at 04:47
  • But does the fiddle above work and not your asp site? The fiddle works fine for me in Chrome and opens in a new tab, and if you did'nt change any browser settings it should for you too, but as others have noted, you can't control the users browser, so you'll never really know for sure how it will open in the users browser, and as such you should'nt really rely on it opening one way or the other. – adeneo Sep 25 '12 at 04:51
  • That's why you shouldn't think that the fiddle is "correct". It's not possible to control, the end. – Ian Sep 25 '12 at 04:54
  • @ianpgall - Yes, we realize that, but if the fiddle works and the OP's site does not, it has nothing to do with user settings, and the OP is probably doing something else wrong. – adeneo Sep 25 '12 at 04:59
  • @adeneo Ahh I see, I assume when they said "this works fine on ie and firefox", they meant both their own code and the fiddle. But in their code snippet above, they have the same as the fiddle, so I don't know what could be done "wrong". – Ian Sep 25 '12 at 05:02
  • It's ASP, all sorts of things can go wrong with that crap :o ?? – adeneo Sep 25 '12 at 05:08

1 Answers1

2

try this:

var newWindow = window.open('http://www.example.com','_blank');

$.ajax({
    type: "POST",
    url: "Performance.aspx/GenerateMatrix",
    data: '{OrgId: ' + $('#hidOrgId').val() + ',SurveyFormId: ' + $('#divMatrixInfo .FeedbackForm').val() + ',GoalId: ' + $('#divMatrixInfo .FeedbackGoal').val() + ',StartDate: ' + "'" + StartDateTime + "'" + ',EndDate: ' + "'" + EndDateTime + "'" + ',EmployeeId: ' + "'" + $('#divMatrixInfo .FeedbackEmployee').val() + "'" + ',QuestionId: ' + "'" + $('#divMatrixInfo .FeedbackQuestion').val() + "'" + '}',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (response) {
                    CloseModelOverLay('divMatrixInfo');
                    newWindow.focus();
                    $('#ddlPDPView').val('Goals');
                    $('#ddlPDPView').change();
    },
    failure: function (response) {
                    alert(response.d);
    }
  });