Tag a open in new tab. CSS: changing the style for links that open in a new window

Problem Solution

By default, links open in the same window where they are located. So that any link opens in a new window, to the tag you should add a target attribute with the value _blank as shown in example 1.

HTML5 IE Cr Op Sa Fx

Links

Please note that using the strict target attribute in HTML4 and XHTML is deprecated and code with it will not pass validation. In this case, in order to make a link to open in a new window and maintain the correctness of the code, HTML and CSS alone are not enough, so you will have to turn to scripts. First, you need to somehow highlight the links that will open in a new window, for example, with the rel attribute with the value external . This attribute briefly describes the link or where it goes. Browsers do not accept this attribute, but it is not required since we will be checking all links through JavaScript (example 2). The same target is added to the necessary links. But since this is done programmatically, the validator will not notice the trick.

XHTML 1.0 CSS 2.1 IE Cr Op Sa Fx

Link in new window /* */

One of the site visitors asked how to open a link in a new HTML window. In this article I will answer this question.

What you will need

The visitor did not specify which editor he uses, so we will assume that it works directly in HTML. But this does not mean that you cannot follow these instructions if you use any visual editor to create a website. You'll just need to access the page layout. Most editors and blogging platforms allow you to manually edit the HTML code.

For example, if you are working in Expression Web, you can edit the page code by switching to Code mode.

How to set links to open in a new tab or new browser window

thesitewizard.com

Change it to look like this:

thesitewizard.com

Now, when users click on this link, it will open in a new window or tab (depending on what browser they are using and how it is configured).

Please note that if you are using a DOCTYPE with strict XHTML 1.0 or 1.1 syntax, you will not be able to use the above code and have the page validated at the same time. But I suspect that no one uses these standards. The "transitional" versions of these standards for opening in a new HTML window are fine for us, and they also support the target attribute.

If you're working in Expression Web, Dreamweaver, BlueGriffon, or KompoZer, click on the link you want to edit, go into HTML edit mode, and add the target="_blank" attribute.

This method doesn't have many advantages.

Many new webmasters think that by opening links in a new window, users are less likely to leave the site. This is fundamentally wrong. If someone clicks on a link and then wants to return to your site, they will simply click the "Back" button. Even the least technically savvy people will learn about this function immediately after getting acquainted with the Internet. Advanced users also know that you can use the “Open link in a new tab” (or “Open link in a new window”) option.

By creating links that open in a new window, you prevent users from returning to your site. It may seem that they will easily return to the first window with your site. My experience is that this is not the case - people are confused by the back button not working. They don't even suspect that there is a new tab or a new window in front of them. When they can't quickly return to the previous page, they simply give up and move on to other resources.

Experienced users fare no better. They are very annoyed by your site’s “habit” of opening new windows without permission. That's why they are experienced users - if they wanted to open a new tab, they would do it themselves, and they don't like it at all that they do it without their consent. It's even worse if all your links open in a new window.

The site becomes vulnerable to phishing attacks

If you use the HTML open in new window button using target="_blank" , the site that the link leads to has access to the window/tab containing your page and can replace its content.

This will not only not keep users on the site (if you opened new tabs for this purpose), but it will also endanger visitors. For example, if you have a user login page, the site located on the link can replace it with a copy of yours, but at the same time collecting user logins and passwords. This type of attack is called “phishing”.

And this is not a theoretical vulnerability. Google security specialists noted a “significant number of reports” about such hijacking of tabs for the purpose of introducing malicious software.

For those who are interested - technical details. The site opened in a new window accesses your page through the window.opener object in JavaScript. This is a read/write object that can be manipulated. Among other things, you can change the window.opener.location property and force the browser to go to the new address to open the image in a new HTML window.

Some browsers allow you to prevent this behavior by adding a rel="noopener noreferrer" attribute to the link. The example given at the beginning of the article would look like this:

thesitewizard.com

In theory, both rel="noopener" and rel="noreferrer" should be enough to protect against such an attack when opening the page in a new HTML window. In this case, it is more correct to use the rel=”noopener” attribute, since rel=”noreferrer” has a side effect - the browser will not transmit the URL of the request source to the site. But at the moment, not all browsers support the rel="noopener" attribute. Likewise, rel="noreferrer" is not supported by some browsers. Therefore, if you want to protect users of as many browsers as possible, you will probably need to use both attributes.

However, this technique only works on current versions of Chrome, Firefox and Safari. Internet Explorer does not support this function, although I quickly checked version 11 of IE, and it seems to be protected from such an attack with the default security settings. I can’t say for sure about the Microsoft Edge browser.

In other words, the method described above cannot be called one hundred percent protection. The best way to avoid this problem is to use normal links without the target="_blank" attribute.

Conclusion

A general recommendation is to avoid opening tabs in a new HTML window if possible. Of course, in some cases this cannot be avoided. In this situation, you can warn site visitors that “link opens in a new window”. This won't help the average user much and won't protect them from phishing attacks through your site, but at least it won't annoy more experienced users.

He will simply lose your page, which will worsen your blog's behavioral factors (view depth and time spent on the site).

How to insert WordPress links when publishing a post

To prevent the reader from losing your blog, when creating a link, click the Open in a new window/tab checkbox.


Publishing an announcement in the Subscribe mailing list

Compared to the WordPress admin panel, when publishing an announcement, you can also use the option to open the link in a new window.

According to the requirements of administrators of many groups, such a link is necessary. They are very concerned that the reader does not leave the group page, stays in touch, and suddenly wants to read something else.

  • highlight the desired word or phrase, click the link icon,
  • in the window that opens, enter the URL of the page you want to go to,
  • select "In new window"
  • write a Title. It will be highlighted when you hover over the link,
  • Click Paste.
HTML link in a new window. How to open

Open the HTML tab => paste the announcement text => paste the following code

Text link - UPDATE HTML tab.

Your website address is the address of the page with the article.

Don't forget to Refresh the HTML tab and then Publish your announcement.

P.S. Is it simple? Please let me know in the comments if this information helped you.

SIMILAR ARTICLES:

FRIENDS, THANK YOU FOR SHARING THE ARTICLE:

6 reviews for “Html link in new window. How to open? ”

    So everything is clear!!! But I need the main menu (top header), the link to open in a new tab, in WordPress in the menu, when you paste the link, there is no checkbox to open in a new tab, what can I do? , but this doesn’t suit me, please help!

  • Yane: In the admin panel “Appearance” - “Menu”. Click. The upper right corner is “Screen Settings”. Click. In the “Show extended menu properties” section, check the “Link target” checkbox. Select the desired menu item to open in a new window. Check the “Open link in a new window/tab” checkbox. Save the menu and enjoy life)))


.

Internet Explorer Mozilla Firefox Working with tabs
in Google Chrome browser






with tabs.

You can find all the complete information about working with tabs in your Google Chrome.

Browser problem: all links open in a new tab

To do this, open your browser and simply press the F1 function key on your keyboard. Or click the wrench icon, or maybe an icon like mine, instead of a wrench, at the end of the browser's address bar. And select Help at the bottom of the tab that opens. A new tab will open with a Tabs and Windows link in the center. Click and all the Headings associated with the tabs will open on the right.

Safari Opera

When you surf the Internet, modern browsers always allow you to open a page via a link in a new window or tab. This is often very convenient - you see an interesting link, but do not look up from the text you are reading, but open the link in a new window or tab to return when you are done with the one currently open. I always wanted this option to be available in Windows Explorer - right-click on a folder - and there is an option there: “open in a new window”.

It’s easy enough to add such an option by going into the properties of Explorer, but don’t do this on every computer you visit! It is much better to automate the process using a reg file. This is the second goal of this article - to continue the topic of the registry and show how it can be edited not only by hand.

In this article I will provide the code for a file that adds an option to the context menu; In addition, this file can be downloaded. If you have interesting examples of registry files, send them to me in the comments!

Note: I apologize to those who were waiting for an article about anonymity. I don't have time. I'm putting it out from stock.

So, the registry.

How to make links open in a new window or tab

If you've already run regedit, you can experiment with exporting the entire registry or part of it yourself. To do this, you need to stand on the registry branch, go to the file-export menu and select where you want to upload. You will get a file with the reg extension, double-clicking on which will restore the registry - load it back. But you can create such a file yourself, which is what we will do now. Create a text file and write the following content inside:

@="Open in new window"

@="C:\\WINDOWS\\explorer.exe \"%1\""

Now the file needs to be renamed - change its extension to reg. How to do it? Exactly the same way you rename other files, only you first need to display the file extensions.

Double-click on such a file, agree to make changes to the registry - and voila, the context menu has been changed - when you right-click on the folder, the "open in new window" option appears. If you don't want to create, edit and rename the file, you can download it from my website.

But this file will make my site the home page in Internet Explorer

Windows Registry Editor Version 5.00

"Start Page" = "https://it.sander.su/"

Do you have good examples of files for editing the registry? Send it! By the way, let me remind you of my old post about Windows script host - there are examples of comic programs in the language built into Windows.

comments powered by

How to open a link in a new window? How to change
tab settings
in browsers

Browsers are initially configured differently to open new pages. For example, Safari is configured to open new pages in a new window. And Mozilla Firefox opens new pages in new tabs on the Tab Bar, but in addition we have the ability to open new windows.
You can change the settings yourself.

Internet Explorer

You can change tab settings in Internet Explorer in Internet Options. Click on the gear icon at the top right of the browser panel. Select Internet Options, then select the General tab and at the bottom, in the Tabs line, click on Options. In the center below the line When opening a new tab, open: select the desired way to open tabs in the black triangle.

Mozilla Firefox

To change tab settings in the Mozilla Firefox browser, click the Tools button on the panel. At the bottom, click Settings. At the very top of the new window, click Tabs. And here you can either check the boxes or uncheck them in the way you want to open new tabs.

Working with Tabs
in Google Chrome browser

I didn't find it in the latest version of Google Chrome
ability to change settings for tabs.
Probably this very convenient and smart browser does not need to change the settings. Because Google Chrome offers users many tabbed options.
Very easy to open a new tab and new
window, even through hotkeys.
Need to open the same web page in multiple tabs
There is an option to Duplicate a tab. There is an opportunity to work
in incognito mode (hidden viewing). You can move the desired one
tab in a separate window. And many more job opportunities
with tabs.

You can find all the complete information about working with tabs in your Google Chrome. To do this, open your browser and simply press the F1 function key on your keyboard. Or click the wrench icon, or maybe an icon like mine, instead of a wrench, at the end of the browser's address bar. And select Help at the bottom of the tab that opens. A new tab will open with a Tabs and Windows link in the center. Click and all the Headings associated with the tabs will open on the right.

Safari

To change settings for tabs in the Safari browser, click the gear icon on the right side of the browser panel. In the new tab, select Settings, and in the next window, select Tabs. And here in the line Open pages in tabs, not in windows: select the option you need.

Opera

In the Opera browser, to change tab settings, click the Tools button on the panel. Select General Settings at the bottom of the new tab. And in this tab, click on the Advanced panel and then the Tab Settings button. The Advanced Tab Settings window will open. Check the box next to the way you want to open tabs and click OK at the bottom.

Go to the main page of the site

Everyone knows how to open a page in a new tab using a link. Add the target="_blank" attribute to the link and rejoice. But by clicking on the button, opening the page in a new tab is a little more difficult. Well, the button does not have a target attribute.

Blog RSS

will open the specified page in the current window, and

Blog RSS

will open in a new tab.

How can I click on a button to open a page in a new tab?

Firstly, in order to open anything at all by clicking on a button, which, moreover, is not in a form block, but by itself, you must use the button's OnClick method.

For example like this:

In this case, the partners.php page will open in the current browser window. But sometimes you need to open a page in a new window or tab. What should I do? In design

It turned out that each button had its own separate function written. Not optimal. Not elegant. Everything worked, of course, but where is the poetry of the code?

Optimal solution

Why bloat JavaScript when you can solve everything with one single function? What if I need to add 5 more buttons like this? Therefore, the solution here is different. There is only one JavaScript function, and each button passes it the desired URL as a parameter.

The final code now looks like this:

As you can see, the button passes the URL as a parameter, and the function accepts it and opens it in a new tab. At the same time, the JavaScript code has become much smaller.

That's all. Now you know how to click on a button to open a page in a new tab. If someone needs it, use it.

Good luck and see you soon.

Related materials:

Gutenberg - uses, nuances and possibilities

How to check a person from a photo

How to properly insert a YouTube video into a blog post