How to change one HTML file for another?

Asked

Viewed 227 times

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 would like to know how I can change, for example, a text from the file h1.html using a button in the file h2.html.

  • You can pass the variable by post and the text will be the received variable if it exists, vc does it using php and html

  • Why are you using frame and frameset? Ps.: Both are deprecated.

  • @Valdemir I’m a beginner, but doing what I’m in the same html will be tiring and disorganized. Woton Sampaio give an example, I’ve never used php xD

  • @Kidnapper I’m really not getting even with the contentDocument, browser is blocking access, I removed the answer while searching for a solution :) A question. You use jQuery?

  • I have imported, but I can not use alone, if you have a code ready.

1 answer

0

Let’s suppose for your example the following structure:

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

In any of iframes, you can access the page Parent (start) with Javascript, and then any page element Parent, including the iframes. So in the example I put in Function who is in the iframe menu, let’s access the input of iframe rest like this:

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

Note: avoid using iframes, they are obsolete and the permissions of some browsers can make them not work. If you need to use separate files there are other more modern alternatives.

  • believe q the code would have worked, the browser blocked the frame from accessing the other because it has "cross-origin" origin. if there is any way to define the source of the file would work

  • yes, the code works, but in your case it will not even be possible, browser security restrictions. Anyway, use iframe is already something obsolete, and still from different domains? Definitely not a good practice

Browser other questions tagged

You are not signed in. Login or sign up in order to post.