简体   繁体   中英

How do I refresh a page when clicking on a href? | HTML, CSS

What do I have:

HTML, CSS, JS

What do I need:

Reload a page when clicking on <a href> .

What do I know:

I can reload a page using window.location.reload() . To use it in HTML code, I have to put it into <script> tags.

What don't I know:

How to execute this script code when clicking on <a href> .

My code:

<ul>
    ....
    <a href="#" class="currentpage"><li>About us</li></a>
</ul>



What have I tried:

Nothing yet. I have no idea how to link the <script> with <a href> .

If you want to reload the current page you can use this code:

 <a href="#" onclick="myFunction()" class="currentpage"><li>About us</li></a> <script> function myFunction() { window.location.reload(); } </script>

It will execute the given function after you click on the link.

You can simply do as below:

<a href="javascript:window.location.reload();"><li>Refresh Page</li></a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM