Yogesh Chauhan's Blog

Safe Practice to add Links to cross-origin destination

in UI/UX on December 1, 2020

When you link to a page on another site using the target="_blank" attribute, you can expose your site to performance and security issues.

For example:

1. The other page may run on the same process as your page.

If the other page is running a lot of JavaScript, your page’s performance may suffer.

2. The other page can access your window object with the window.opener property.

This may allow the other page to redirect your page to a malicious URL.


Adding rel="noopener" or rel="noreferrer" to your target="_blank" links avoids these issues.

How to improve your site’s performance and prevent security vulnerabilities 

Add rel="noopener" or rel="noreferrer" to each external link.

When you use target=”_blank”, always add rel=”noopener” or rel=”noreferrer”.

After doing that your link will look similar to this:

<a href="https://example.com" target="_blank" rel="noreferrer">

OR if you’ve used rel="noopener" then your link will look similar to this:

<a href="https://example.com" target="_blank" rel="noopener">

💡rel=”noopener” prevents the new page from being able to access the window.opener property and ensures it runs in a separate process.

💡rel=”noreferrer” has the same effect but also prevents the Referer header from being sent to the new page. 

Credit: Web Dev

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
5 Key Principles Of Good Website UsabilityUI/UXGeneral concepts in DrupalDrupalJavaScript String fromCharCode() MethodJavaScriptWhat is an API?MiscellaneousHow to find the HCF or GCD and LCM of two given numbers using Swift?SwiftHow to add CurrencyPipe in TypeScript file in Angular 9 Project?Angular