How to Disable Clickable Links on a Website
- 1). Launch Notepad or your HTML editor. Open one of your Web pages and paste the following HTML code in the document's body section:
<a href="/links/?u=http://www.whitehouse.gov">Visit the White House</a>
<a href="/links/?u=http://www.irs.gov">Visit the IRS</a>
<input type="button" value="Open Drop Down" onclick="disableLinks()" />
The code creates two links and a button. The button calls a JavaScript function called "disableLinks" which disables the links when clicked. - 2). Paste the following "disableLinks" JavaScript function into to your document's script section:
function disableLinks() {
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
var link = links[i];
link.removeAttribute('href');
}
This function stores all links in the "links" variable, then uses the "removeAttribute" method to remove the href attribute from each link. - 3). Save the document, launch a browser and open that document in the browser. Click the "Visit the White House" link. Your browser navigates to the White House website.
- 4). Click the browser's "Back" button to return to your Web page. If the White House link opened in a new tab, return to the tab that contains your Web page.
- 5). Click the "Disable Links" button, then click one of the links. Nothing happens because the button click called the JavaScript function that disables the links.