","image":"http://www.luping.net/uploads/20241107/1730952727672c3e1793ae3.jpg","datePublished":"2024-11-08T15:37:24+08:00","dateModified":"2024-11-08T15:37:24+08:00","author":{"@type":"Person","name":"luping.net","url":"https://www.luping.net/articlelist/0_1.html"}}
"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Prevent Page Reloads When Changing Anchor Tag href Attribute with JavaScript?

How to Prevent Page Reloads When Changing Anchor Tag href Attribute with JavaScript?

Published on 2024-11-08
Browse:590

How to Prevent Page Reloads When Changing Anchor Tag href Attribute with JavaScript?

Changing the href Attribute of an Anchor Tag Using JavaScript on Button Click

In web development, the need to dynamically modify the href attribute of an anchor ...jhhghj

Alternatively, you can prevent the page from scrolling using:

...jhhghj

or return false from the f1() function:

function f1() {
    document.getElementById("abc").href = "xyz.php";          
    return false;
}

...jhhghj

For a more unobtrusive approach, employ an external JavaScript file:

...jhg
...jhhghj

document.getElementById("myLink").onclick = function() {
    document.getElementById("abc").href = "xyz.php";
    return false;
};

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3