How to open a new window in chrome
There are several ways to open a new window in Chrome:
1. Using the window.open()
method:
window.open('https://www.example.com', '_blank');
This will open a new window with the specified URL. The _blank
argument specifies that the new window should be a blank page.
2. Using the chrome.tabs.create()
method:
chrome.tabs.create({ url: 'https://www.example.com' });
This method creates a new tab with the specified URL. Note that this method only works in Chrome extensions.
3. Using the chrome.windows.create()
method:
chrome.windows.create({ url: 'https://www.example.com' });
This method creates a new window with the specified URL. Note that this method only works in Chrome extensions.
4. Using the target
attribute in an HTML link:
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_blank">Open in new window</a>
This will open the link in a new window when clicked.
5. Using the rel
attribute in an HTML link:
<a rel="nofollow" target="_blank" href="https://www.example.com" rel="noopener noreferrer">Open in new window</a>
This will open the link in a new window when clicked, and also set the noopener
and noreferrer
attributes to prevent the new window from accessing the parent window's context.
6. Using the Chrome DevTools:
You can also open a new window in Chrome using the Chrome DevTools. To do this:
- Open the Chrome DevTools by pressing
F12
or right-clicking on the page and selecting "Inspect". - In the DevTools, click on the "Elements" tab.
- In the Elements tab, click on the "New Window" button (looks like a window icon).
- Enter the URL you want to open in the new window and click "Open".
Note that some of these methods may have limitations or restrictions, such as requiring permission from the user or being limited to specific contexts (e.g. Chrome extensions).