Page-long .html
, you can do this using Javascript. You can do this by following the steps:
1. Add to hash with the id
of div
that you will carry on href
of the link to index.html
:
<a href="servicos.html#id_da_div">Serviços</a>
2. On the page servicos.html
capture the hash with window.location.hash
. But create two iframe
s, one without src
and the other hidden with display: none
with the page desc_servicos.html
.
Why two iframes being one hidden? What is not hidden will receive the div
of the other who is hidden. That’s because the iframe
occult is
that will load the page desc_servicos.html
and you don’t have to show up,
because it will be fully loaded so that one can catch the div
desired.
Would look like this:
<iframe id="frame" width="500" height="200"></iframe>
<iframe id="frame2" style="display: none;" src="desc_servicos.html"></iframe>
And include the script below (at the end of body
) page servicos.html
:
<script>
var iFrame = document.body.querySelector("#frame");
var iFrame2 = document.body.querySelector("#frame2");
var div_id = window.location.hash;
iFrame2.onload = function(){ // aguarda o iframe2 carregar
// insere a div no iframe visível
iFrame.contentDocument.body.innerHTML = iFrame2.contentWindow.document.querySelector(div_id).outerHTML;
iFrame2.outerHTML = ''; // remove o iframe2 do DOM
}
</script>
In short:
On the page index.html
(substitute id_da_div
for id
of div
there’s iframe
you want to take):
<a href="servicos.html#id_da_div">Serviços</a>
On the page servicos.html
:
<iframe id="frame" width="500" height="200"></iframe>
<iframe id="frame2" style="display: none;" src="desc_servicos.html"></iframe>
<script>
var iFrame = document.body.querySelector("#frame");
var iFrame2 = document.body.querySelector("#frame2");
var div_id = window.location.hash;
iFrame2.onload = function(){ // aguarda o iframe2 carregar
// insere a div no iframe visível
iFrame.contentDocument.body.innerHTML = iFrame2.contentWindow.document.querySelector(div_id).outerHTML;
iFrame2.outerHTML = ''; // remove o iframe2 do DOM
}
</script>
Nice to see you!... whatever it is just to call
– Sam
dvd, worked perfectly. Thank you very much for your instruction and congratulations on your teaching. Now I have to format the called information, because I believe that when it loads the frame2 and sends it to frame I believe I miss the training. I don’t know Javascript yet, but I’ll get there!
– Diego Primo
The complete answer above!!
– Diego Primo