C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Disable new tab opening of links using JQuery
WhatsApp
Sudheer Kumar
5y
56.3
k
0
2
25
Blog
Below JS function will use for disabling the new tab functionality and it will throw the alert message.
function
disableNewTabClick() {
var
listCtrl = document.getElementsByTagName(
'a'
);
for
(
var
i = 0; i < listCtrl.length; i++) {
listCtrl[i].onmousedown =
function
(event) {
if
(!event) event = window.event;
if
(event.ctrlKey) {
alert(
"Functionality for Opening links in a new tab/window is disabled !"
);
return
false
;
}
if
(event.shiftKey) {
alert(
"Functionality for Opening links in a new tab/window is disabled !"
);
return
false
;
}
if
(event.shiftKey && event.ctrlKey) {
alert(
"Functionality for Opening links in a new tab/window is disabled !"
);
return
false
;
}
}
}
}
People also reading
Membership not found