I want to thanks those who are currently reading this and for your time. Let's go straight to the topic!
I am currently trying to disable a feature where a user should not be able to open a link to a new window or tab by holding down on a link.
Any suggestions or answers to approach this problem is appreciated, Thanks again!
You could bind an event handler to the desired link element and use jQuery's .preventDefault()
method to cancel the link going anywhere. Your code would look something like this:
$('a').click(function(event){
event.preventDefault();
});
If you need to prevent the user from opening links in a separate tab or window, then there's probably something wrong with your site design. Why do you feel that this restriction is necessary?
But to answer your question -- one way to more or less guarantee this, without depending on JavaScript and/or browser quirks, and without breaking too many any other important browser features, is to have each "link" actually be a form-button: <form method="GET" action="http://example.com/..."><input type="submit" value="click here for more information" class="pseudo-link-input" /></form>
, with lots of CSS styling to make the button look like a link.
Caveats:
<input type="hidden" .../>
elements. (And this requires that the query strings be of the type that can be constructed by an HTML form.)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With