This is possible with Javascript. You have two alternatives:
- go through the URL
- store in the localStorage
HTML example
Assuming the content you want to pass is this:
<p id="comentario">Hoje está um lindo dia!</p>
Going through the URL
You can insert this text into the URL that opens the next tab. The format will be
http://teusite.com/pasta/subpasta?comentario=Hoje%20est%C3%A1%20um%20lindo%20dia!
The part of the URL after ?
is called querystring and exists to pass data between pages or server.
To insert content into the URL you will need to change the links in the HTML. The best way is with Javascript using encodeURIComponent()
which is a native method for converting text into accepted format in the URL.
So you have to find the link you want to open the next page and change:
Example:
HTML
<a id="ancora" href="novapagina.html">Clique aqui</a>
Javascript
var texto = document.getElementById('comentario').innerHTML;
var ancora = document.getElementById('ancora');
ancora.href = ancora.href + '?comentario=' + encodeURIComponent(texto );
This way, when the link is clicked it will open the new page with information in the URL/Querystring.
And how to read this on the new page?
To read this on the new page uses the location.search
to give you the querystring and then remove what interests you:
Javascript
var qs = location.search;
var textoDesformatado = qs.split('=');
var textoFinal = textoDesformatado[1] && decodeURIComponent(textoDesformatado);
// e depois, para inserir no novo <p id="comentario"></p> basta fazer
document.getElementById('comentario').innerHTML = textoFinal;
Note:
you can also open a new Javascript page directly. In this case it would be something like:
location.href = '/pasta/subpasta?comentario=' + encodeURIComponent(texto );
Going by the localStorage
The Storage location is the browser memory and is active even after shutting down the computer. In other words, the computer writes to an internal file in the browser and I saw it later.
So to write to localStoragd just do:
localStorage.comentario = document.getElementById('comentario').innerHTML;
and, on the new page, to read the code just do the opposite:
document.getElementById('comentario').innerHTML = localStorage.comentario;
Note:
There are more alternatives using the server, but I don’t include them because you only mentioned client-side technology.
You can better explain how you navigate between pages, if they are in the same domain?
– Sergio
Have you done anything? Show some code.
– user14869
Do you want to take a paragraph from one HTML page to another HTML page? For this you can use Javascript, with different ID in HTML.. But I believe that you are a little confused or explained wrong.
– Giovanni Bernini
css3 is technology to style pages and not to "load pages". I think you need to first understand what each technology does.
– Guilherme Nascimento