Manipulate an iframe through another iframe

Asked

Viewed 943 times

1

Hello, I have a question and I would like to ask for your help. Well, I’ll try to explain more or less the problem (the names I’ll quote are just for example).
Imagine I have a file called "main.php", then inside this file has two Iframes:

  • The first iframe contains the file "iframe1.php"
  • The second iframe contains the file "iframe2.php".

  • Now let’s imagine that I have the first iframe open in modal format (or fancybox), and I want through this first iframe, I can reload the other iframe that is also referenced in the file "main.php".

    I had tried that way, but unfortunately it didn’t work:

    window.parent.$('#iframe-sistema').location.reload(true);

    Just to be clear. "iframe1.php" would be a data listing iframe that comes from the database, that when clicking delete, it will open "iframe2.php" in modal format (or fancybox,popup,etc) that will ask if I really want to delete that record.
    After confirming the deletion, this same iframe (the "iframe2.php") will display a message if everything went right and after pressing the "ok" button, it will auto close and reload the "iframe1.php" to show the records that remained after deleting a record.
    I know that to some this may seem like excessive use of iframe, but the point is that this is a system that’s going to be very modular, where the use of code has to be reusable so that there is no repetition of code and consequently end up generating a heavy and difficult maintenance system. If anyone also knows an alternative solution for using iframes, I appreciate it. = D Note: (I use Jquery’s load() function in some parts of this system, but I don’t know if it can work in this situation).

    • Are the two iframes in the same domain? why don’t you do it without iframe?

    • Yes. Even the references of the two iframes are in the same file. I don’t really like to use iframes, but in this case I haven’t found an alternative use of iframes.

    • If you describe what you want to do we understand the problem better and you might learn a better way to do it...

    • OK. I will try to improve the description of the problem.

    • Lucas: forget the idea of iframe! Do it with the .load(). A div that displays what you want with dynamic content and the dialog to interact (ask for confirmations) from the user. If you put more code on the page I can give a hint during fds. If no one helps before.

    • Thanks for the help, I’ll try the way you said. Anything I come back here to talk the result.

    • @Lucascavalcanti, since you yourself solved your problem, could perhaps remove the solution from the question and create an answer to your own question by explaining your solution. It would be easier to identify the solution to your problem (I read the whole question to later find that it was solved, =D), and it is still possible to receive votes in your answer.

    • Thank you. I’ll do that ;)

    Show 3 more comments

    1 answer

    0


    Solution:

    I tried to follow Sergio’s idea of using "load()", but in my case this is a bit difficult to use. I particularly prefer the load, because the code can load faster, but I would have to mix many JS, CSS files in the same file, so I opted to use the same iframe. That way, I was able to update an iframe through another iframe:

    window.parent.document.getElementById(iframe).contentDocument.location.reload(true);

    Browser other questions tagged

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