javascript - How to open URL in same window and in same tab - Stack Overflow

I have this LinkButton:<asp:LinkButton ID="lbiOpen" runat="server" >and my C

I have this LinkButton:

<asp:LinkButton ID="lbiOpen" runat="server" />

and my Code behind:

protected void Page_Load(object sender, EventArgs e)
{
    lbiOpen.Attributes.Add("onclick", "javascript:window.location.href('New.aspx');"); 
}

If a user clicks on the LinkButton a popup should open. But it doesn't work. When I click on nothing happens.

When I Change window.location.href = window.open it works, but it opens in another tab.

I have this LinkButton:

<asp:LinkButton ID="lbiOpen" runat="server" />

and my Code behind:

protected void Page_Load(object sender, EventArgs e)
{
    lbiOpen.Attributes.Add("onclick", "javascript:window.location.href('New.aspx');"); 
}

If a user clicks on the LinkButton a popup should open. But it doesn't work. When I click on nothing happens.

When I Change window.location.href = window.open it works, but it opens in another tab.

Share Improve this question edited Mar 21, 2017 at 9:40 Tetsuya Yamamoto 25k8 gold badges42 silver badges63 bronze badges asked Mar 21, 2017 at 9:37 Olga Olga 1173 silver badges9 bronze badges 4
  • Did you try "javascript:window.location.href='New.aspx';" – GavinBrelstaff Commented Mar 21, 2017 at 9:39
  • Why do you need it to be asp:LinkButton and not simple a href? – klashar Commented Mar 21, 2017 at 9:39
  • window.location.assign("New.aspx"); – CaptainHere Commented Mar 21, 2017 at 9:40
  • Posted how to open on a new window ^^ – Marco Salerno Commented Mar 21, 2017 at 9:49
Add a ment  | 

3 Answers 3

Reset to default 2
window.open("New.aspx", "_self"); // will open in the same windows

window.location.href = "New.aspx"; // will open in a new window

This works for me:

<asp:LinkButton ID="lbiOpen" runat="server">Example</asp:LinkButton>


    protected void Page_Load(object sender, EventArgs e)
    {
        lbiOpen.Attributes.Add("onclick", "window.open('New.aspx', 'New Window', 'width=200,height=100')");
    }
<asp:LinkButton ID="lbiOpen" OnClientClick="window.open('New.aspx', '_self');return false;" Text="Submit" runat="server" />

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744251001a4565166.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信