rel='noopener' Keeps You Safe and Fast

rel=noopener Stops Malicious Attacks
rel=noopener Stops Malicious Attacks

When a hyperlink opens a new browser window or tab you should add the rel="noopener" attribute to the link. This prevents the new page from reaching back to control the initial page.

Anytime you open a new window using the method or with a hyperlink using the target attribute. By default the new page has access to the window.opener object, which can be used to drive the original page.

It is common to open external links in a new browser window. This means the visitor does not 'leave' your site for the target site. The two ways to do this are using anchor tags with the target attribute set to the new window's name:

<a href="{external url}" target="_blank">anchor text</a> 

The other way is via JavaScript using"external url");

As you can imagine this opens up a variety of potential security issues. Fortunately you can disable this property by adding the rel="noopener" attribute to hyperlinks.

You will also see how opening new browser tabs opens you up to performance issues because you are inheriting the target page's performance issues.

The Security Issue of Opening a New Browser Window

Maybe you control all the external pages you link to, by that I mean you only link to pages you feel you can trust. But as soon as you allow user generated content, like comments, you have outsourced control of those target pages to someone you don't really know.

They could link to anything, including a malicious site.

Over time the pages you link to change. Domains expire and 'bad guys' purchase them. Now you have a link to a bad site and worse, it could be used to control your page.

The number one problem is the new page could reach back to your page and access the navigator.location object. This means they can change the page loaded in your window.

Now they have complete control over the page in the tab where you page once was. You may have linked to what you think is a 'clean' page, but it could be hiding a script to change your page to their malware page.

Once they change your page to their page they could do anything they want and you were the gateway to loading the page.

It is a bit trickier to shield against this attack when you open pages using JavaScript.

You could create a reference to the new window and set the opener property to null like this:

var newWindow =; newWindow.opener = null; newWindow.location = url; 

In this example you create reference to a new window, set the opener to null and then set the new window's location. Now the new page will have no access to the opener object because it simply does not exist.

You can also create a temporary iframe to open the new tab. Once the new tab opens you can then delete the iframe. This removes the window.opener reference in the new page.

Lighthouse Reporting Unsafe Cross Origin Links
Lighthouse Reporting Unsafe Cross Origin Links

Performance Impact

A few years back Jake Archibald wrote about this same topic and discussed how using the noopener has a positive performance impact.

To understand why opening a new window poses performance issues you need a little primer on how browsers work. Each window is more or less single threaded. The new window opened when a link using the target attribute is clicked runs in the same thread.

Now the new window's rendering and script parsing runs in the same thread as your page. This means you are allowing someone else's code to slow your page's ability to respond to the user.

If you are not aware most web pages use excessive and slow JavaScript, especially pages with cascading third party requests. All those scripts are now your scripts.

When you use the rel="noopener" attribute the second window is executed within its own thread, freeing your page from suffering from the target page's performance issues.

So now you are not only protecting against a potential security issue you are protecting yourself from inheriting performance problems the target page has and maybe their malicious third party scripts.


It may seem innocuous and simple, but the this little trick can save you and your customers some grief later on. Make sure any link on your site using the target attribute uses the rel="noopener" attribute.

You will also want to make sure any external pages you load via the JavaScript method are isolated as well.

Even if the target page is not owned by a bad actor, you need to guard against performance impact due to their poor page architecture.

Make sure your web pages always use the rel=noopener when opening external links in a new window to prevent access to your window.

Share This Article With Your Friends!

We use cookies to give you the best experience possible. By continuing, we'll assume you're cool with our cookie policy.

Install Love2Dev for quick, easy access from your homescreen or start menu.

Googles Ads Facebook Pixel Bing Pixel LinkedIn Pixel