How to change one HTML file for another?

0

I have the files:

  • h1.html
  • h2.html
  • start.html

Start.html:

<frameset cols='20%, *'>
<frame src='h1.html' name='menu'>
<frame src='h2.html' name='resto'>
</frameset>

I'd like to know how I can change, for example, text from the h1.html file by using a button in the h2.html file.

    
asked by anonymous 27.02.2018 / 04:50

1 answer

0

Let's assume for your example the following structure:

start.html
   h1.html (iframe menu)
       function alterarInput()...
   h2.html (iframe resto)
       <input id="input1" />

In any of the iframes , you can access the parent (start) page with Javascript , and then any parent element, with%. So in the example I put in the function that is in the iframes menu, let's access the iframe of the input rest like this:

function alterarInput() {
   parent.resto.document.getElementById('input1').value= 'novo valor';
}

Note: avoid using iframe , they are obsolete, and the permissions of some browsers may prevent them from working. If you need to use separate files there are other more modern alternatives.

    
27.02.2018 / 12:19