Saket
Saket

Reputation: 441

How to disable new tab option in google chrome on a href using javascript

I have an application which has multiple a href links. On right click they display "New Tab" in Chrome browser. On clicking that it opens a new tab ,but the application is not designed to work in a new tab. Is there any way to disable that option or catch the event of a new tab in Chrome. Thanks

Upvotes: 1

Views: 5385

Answers (2)

icaru12
icaru12

Reputation: 1582

The links open in new tab based on its target attribute, the target attribute specifies where to open the linked document. Just remove target="_blank" from <a> tag or set target="_self"

Upvotes: 0

Uooo
Uooo

Reputation: 6334

No, that is not possible. It is a browser feature to open links in new tabs. That's, among others, the purpose of a link <a> tag.

However, you can use e.g. a <span> tag and attach an onclick handler on it to perform page navigation:

<span onclick="window.location.href='nextpage.html'">Next page</span>

Using CSS you can style the span to look like a link.

Upvotes: 2

Related Questions