Goldentp
Goldentp

Reputation: 197

How do I close a window after clicking a button?

I am using MVC 3 and I have a button that the user presses to either update some records or to not update some records. I am trying to close the tab after the user presses the No, thank you button. After doing some research all that I have been able to find on this subject is to close a window using jQuery or javascript. I was hoping that there is a way to close the window in the actionLink. I have included the button code below and feel free to ask any questions you might have as I will be checking back often. If you need any other code I would be happy to supply that as well. Thanks for your help!

<div class="message dialog" title="Changes Saved">
            You have successfully saved your changes.<br/>Would you like to update the other versions of this Project?
            <br />
            @Html.ActionLink("Yes, Update Projects", "UpdateProject", "Project", new { id = Model.IAMP_PK }, new { @class = "button2" })
            @Html.ActionLink("No, Thank you", null, null, new { @class = "button2" })
            </div>

Upvotes: 2

Views: 16652

Answers (3)

user10785458
user10785458

Reputation: 11

It is very simple to close window or tab which is related to our current project.

After Create a Button with onclick function name(closeWindow) use the below code.

function closeWindow() {
    alert("Your Tab is closing.....");
    //window.open('', '_self', '');
    self.close();
}

Upvotes: 1

Mohayemin
Mohayemin

Reputation: 3870

You cannot close the browser from server-side. And I am not sure why you want that when client-side solution is pretty simple.

Change the button to:

@Html.ActionLink("No, Thank you", null, null, new { @class = "button2", id="close" })

Then do

$("#close").click(function() { window.close(); });

Upvotes: 4

Shawn
Shawn

Reputation: 1891

javascript is answer as client-side code is only way to close the browser. You could attach a jquery onclick event to the button based on class=button2.

http://api.jquery.com/click/

$(".button2").click(function() { window.close(); });

How to close current tab in a browser window?

Upvotes: 2

Related Questions