最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin6浏览0评论

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" />
发布评论

评论列表(0)

  1. 暂无评论