JS Function for Multiple Links

I have a web page with several links, and each link needs to open in a new, resized window.

Here is how I am doing it for a single link with an inline script:

<h4 style="text-align: left;">
  <span style="font-size: x-large;">
    <a title="Link Title" href="#" target="popup" onclick="window.open('#','popup','width=800,height=400'); return false;" rel="noopener">Link Text</a>
  </span>
</h4>

I would like to avoid doing this for each link, and instead have a single function that can be used to open all specified links in a new resized window.

I’m a little stuck on how to accomplish this. All solutions for this seem to have the URL in the function. Any directions or thoughts on how to accomplish this would be greatly appreciated.

Thanks!

Welcome to Community :slight_smile:

You can achieve this by using Class.

Here is the code for that. We have given a Class to all those links which we have to open in Popup Window and make a single function for that.

  <a title="Link Title" href="index.html" target="popup" class="popUplink"  rel="noopener">Link Text</a>
   <a title="Link Title" href="contact.html" target="popup" class="popUplink" rel="noopener">Link Text</a>

Jquery

 $(".popUplink").click(function(){
            var hyperLink = $(this).attr('href'); // This will fetch the URL of the link
            console.log(hyperLink);
            window.open(hyperLink, 'popup', 'width=800,height=400'); return false;
 });

I hope you want the same thing which I have mentioned above.

Here is a simple Codepen

Hi, thank you for taking the time to reply!

I tried this out and it is not opening in a new, resized window, only in a new tab.

I was able to get it to work, thank you!

1 Like

Have you checked the CodePen .
I have rechecked and the page are opening in popup (resized window).


If you have get it what you want with your code, then can you please share the code , how you have accomplished the same…

Thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.