简体   繁体   中英

Make clickable div open the URL in a new page

So, I am making a website and I wanted to make the div clickable, instead of using the anchor tag. I did it like this: <div onClick="location.href='URL';" and it worked, but I want it to open the URL in a new page. I tried adding target="_blank" but unfortunately it didn't work. Does anyone know how to do it or if it's possible at all?

<div onClick="window.open('URL', '_blank').focus();"></div>

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