简体   繁体   中英

Open a pop-up on clicking anchor instead of new window

I want to create a link to a pop-up. My problem is, when I click the button for the first time, it will render a pop-up but, when I click it further, it will open new windows.

I want to make sure that, only one pop-up gets rendered and, prevent opening of new windows when clicked multiple times.

<a class="nav-link" href="visitor.html" target="popup" onclick="window.open('visitor.html','name','width=600,height=600')">Some Text</a>

You are trying to open a new window in two different ways, using anchor ('href') and using JavaScript, which may lead to opening of two different windows. In your case, the JavaScript renders the desired popup whereas, the anchor tag opens the new window.

I suggest removing the anchor tag and use mere JavaScript to solve your issue. Please find the below code for your reference.

<span class="nav-link" onclick="window.open('visitor.html','name','width=600,height=600')">Some Text</span>

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