Reputation: 3
I want to close the current tab.
This is what I've got so far.
<a href="javascript:window.open('','_self').close();">Close Me</a>
It displays a link. But I want to a button. How to use it in a button?
Upvotes: 0
Views: 1161
Reputation: 5235
Use just input
tag. Put script into its onclick
attribute. Example:
<input type="button" onclick="window.open('','_self').close();" value="Close Me" />
There's no need for that javascript:
part in onclick
attribute. According to w3, using inputs outside forms is valid when you're using html version > 4.01:
The elements used to create controls generally appear inside a FORM element, but may also appear outside of a FORM element declaration when they are used to build user interfaces. This is discussed in the section on intrinsic events. Note that controls outside a form cannot be successful controls.
Ref: http://www.w3.org/TR/html401/interact/forms.html#form-controls
Upvotes: 1
Reputation: 15553
Use the onClick
attribute of the button.
<button type="button" onClick="javascript:window.open('','_self').close();">Close Me</button>
Upvotes: 1