简体   繁体   中英

Open new tab and also redirect original tab to new page

On a web form I have an asp:button with the OnClientClick set to some javascript, the script opens a new tab then the code behind the button does a Response.Redirect, leaving the original page open in the original tab.

How can I amend this so that a Response.Redirect also happens on the original tab also? IE new tab opens with booking.aspx as per code below, but original tab CurrentPage.aspx changes to NewPage.aspx?

script:

<script type = "text/javascript">

        function SetTarget() {

            document.forms[0].target = "_blank";

        }

</script>

button code-behind:

protected void btnGo_Click(object sender, EventArgs e)
        {
            Response.Redirect("booking.aspx?id=" + lbBooking.Text + "&flag=exists");

        }

Try this:

function SetTarget() { 
    document.forms[0].target = "_blank"; 
    window.location.href = 'YourURL'; 
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM