Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the title for the new browser tab?

I have a question about the new tab for the link.

Is there anyway I can set the browser tab title before user clicks a link? It seems like there is no way to debate the title for the new tab if the html contained in the new tab doesn't have title attribute. Am I right? How do I set the title?

//the href is dynamic so I can't set them one by one because I have 100+ html file here
<a href="test.html" target="_blank">open me<a>
like image 365
BonJon Avatar asked Jan 08 '15 17:01

BonJon


People also ask

What is the title of my browser tab called?

The title that appears in your browser tab is called the page title. If you do not enter a page title, the title of your home page is displayed.

How do I edit my browser tab page title?

The title that appears in your browser tab is called the page title. If you do not enter a page title, the title of your home page is displayed. If you do not enter a title for your home page, then the site name is displayed. You can edit your browser tab page title at any time. Click Menus & Pages on the left side of the Editor.

How to add text to the browser tab of your website?

For example, consider we want to add a text called Home to the browser tab when the user visits the home page of your website. So for that, we can use the title HTML element tag and put the text inside the opening and closing block of the title HTML tag. <!DOCTYPE html> <!--

What is a tab name in chrome?

Like almost any other browser, Chrome takes the title of a website and displays it as the tab name. Since most websites use meaning full titles for their pages, grabbing the title and setting it as the tab name is generally fine.


Video Answer


1 Answers

I have not seen addEventListener work reliably, especially when opening a new page using javascript. The best way to change the tab title and have it work reliably is to set a timeout until the page loads. You may have to play with the timeout value, but it works.

var newWindow = window.open(url, '_blank');

setTimeout(function () {
    newWindow.document.title = "My Tab Name";
}, 100);
like image 68
Wannabe Coder Avatar answered Sep 23 '22 01:09

Wannabe Coder