2

I am using below code for open page in popup window.

ScriptManager.RegisterStartupScript(Page, GetType(Page), "OpenWindow",     "window.open('URL');", True)

But i want to page open in New Tab. Can any one help me in that.

Aamir Shahzad
  • 6,683
  • 8
  • 47
  • 70
Sumanta
  • 313
  • 2
  • 6
  • 17

7 Answers7

1

You will need to make the JavaScript call a user initiated event.

Please see this question and answer for further details (specifically, see point 3 in the answer).

Working example.

<input type="button" value="Click Me" onclick="openWindow()" />

function openWindow() { window.open('http://www.google.com/', '_blank'); }

Community
  • 1
  • 1
angus
  • 690
  • 10
  • 26
  • @angsuf yr answer is good. i have smiler prob --> can u say how to do this operation from code file because this thing causing popup and that popup block by browser.. we have to manually allow popup then after it work.. – Shirish Mar 18 '14 at 10:51
  • @Shirish do you mean to open a new window from the code behind or do you mean to create the JavaScript function and set the onclick attributes from the code behind? – angus Mar 18 '14 at 22:51
  • 1
    @angsuf yes i want to open new window from code behind, I am using like this function.. ScriptManager.RegisterStartupScript(this, this.GetType(), "onclick", "javascript:window.open('../default.aspx','_blank');", true); but every time it cause popup and browser blocker block popup in all browsers.. – Shirish Mar 19 '14 at 03:54
  • @Shirish your code is just running the script to open the popup on the page load. A user will need to initiate the popup using a control that calls the JavaScript function. The answer I provided is relevant to you also. Point 6 `6. Some popup blockers will allow windows opened from user initiated events, but not those opened otherwise.` – angus Mar 19 '14 at 04:24
0

You can use ClientScript.RegisterStartupScript

I tried In Google Chrome its working but Not In Firefox In aspx Code

 <asp:Button Text="" OnClick="Button1_Click" ID="Button1" runat="server" />

In C#

protected void Button1_Click(object sender, EventArgs e)
{
    string queryString = "test.aspx" ;
      string newWin = "window.open('" + queryString + "','_blank');";
    ClientScript.RegisterStartupScript(this.GetType(), "pop", newWin, true);
}

In VB

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim queryString As String = "test.aspx" 
    Dim newWin As String = "window.open('" + queryString + "','_blank');";
    ClientScript.RegisterStartupScript(Me.GetType(), "pop", newWin, True)

End Sub
Dgan
  • 10,077
  • 1
  • 29
  • 51
  • This code is not working. I tried this code but page is not open. My code is working but it open Popup window i want to open New Tab. – Sumanta Mar 18 '14 at 04:42
0

Try replacing this with your script

window.open('URL', '_blank')

and I think it's browser setting that decide whether to open new window or tab. Have a look in to that as well.

found this; If nothing works try this link

voddy
  • 950
  • 1
  • 11
  • 21
0

You can try this..working for me in all browsers...

ScriptManager.RegisterStartupScript(this, this.GetType(), "onclick", "javascript:window.open(

'URL','_blank','height=600px,width=600px,scrollbars=1');", true);

Please Mark as answer if it satisfies you..

Jameem
  • 1,840
  • 3
  • 15
  • 26
0

check this example for you,

 ScriptManager.RegisterClientScriptBlock(btnsave, this.GetType(), "Open",
"window.open('GenerateDCNoPrint.aspx?indentno=" + ddlindentno.SelectedItem.Text + 
"&orderno=" + ddlindentno.SelectedValue + "&lorryno=" + txtlorryno.Text.Trim() + 
"&depaturetime=" + txtdeparture.Text.Trim() + "&date=" + txtdate.Text + "', 
'_blank','dependent,resizable=yes,scrollbars=yes,top=0,height=600');", true);
Sambasiva
  • 1,034
  • 3
  • 16
  • 29
0

try this

Page.ClientScript.RegisterStartupScript(this.GetType(), "OpenWindow", "window.open('WebForm2.aspx', '_blank');", true);

or

 string url = "WebForm2.aspx";
 string s = "window.open('" + url + "', 'popup_window', 'width=300,height=100,left=100,top=100,resizable=yes');";
 ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
Sangram Nandkhile
  • 17,634
  • 19
  • 82
  • 116
Zeud
  • 1
  • 1
0

I have searched and tried many solutions but finally, this works for me.

ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "newWindow", "window.open('google.com','_blank','status=1,toolbar=0,menubar=0,location=1,scrollbars=1,resizable=1,width=700,height=400');", true);
4b0
  • 21,981
  • 30
  • 95
  • 142
Rahul
  • 21
  • 3