How do I open a link in a new tab with JavaScript?
This is my current code:
<button id="homePage" class="float-left submit-button">Home</button>
<script type="text/javascript">
document.getElementById("homePage").onclick = function () {
location.href = "https://www.google.com";
};
</script >
You can use window.open(url, '_blank');
after the location.href
.
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.