I need to know exactly how to return the title of the page:
<title> nome </title>
Returning this way:
You are on the 'name' page.
I've seen a question about a few years but I could not.
I need to know exactly how to return the title of the page:
<title> nome </title>
Returning this way:
You are on the 'name' page.
I've seen a question about a few years but I could not.
Just use the title
property in document
. You can also use this property to change the title of the page.
console.log('Você está na página '${document.title}'');
console.log('Você está na página ' + document.title); // Sem string template
document.title = 'Novo Título'; // Alterando o título
console.log('Agora o título da página é '${document.title}'');
<title>Teste</title>
See more in document.title
in MDN .
You have to use javascript for this:
Applying the following code, for example:
document.getElementById("seuelemento").value = document.title;
You assign the title value to a field with the "id" id
How can example
<input type='text' id='seuelemento'>
The exact javascript code for you to get the title name of a page is:
document.title
You can use the DOM function: getElementsByTagName and access the internal content of this TAG.
document.getElementsByTagName("title")[0].innerHTML
The difference is that this function returns a vector with all elements of the TAG type specified.
And therefore you will have to manipulate the correct index of that target element.