0

So I stupidly decided to make my website using i-frames to load pages so that I could keep a sidebar on the main page and not have to go through and change this each time. What I should have done is the opposite where the sidebar is in the Iframe. My question is, is there anyway I could could use the URL to load a specific page into this Iframe?

E.g http://example.com/gallery and use this to load the gallery page into the I-Frame. To load each page into the Iframe from the sidebar I am using

<a href="gallery.html" onclick="UpdateIFrame()" target="displayframe">Gallery</a>

where UpdateIFrame() is just closing the sidebar and updating the length of the I-Frame.

I was thinking of somehow using JS to read what the URL is or have it point to a file that will load the correct page however I am unsure of how to go about this.

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
  • 1
    [How to create a Minimal, Reproducible Question](https://stackoverflow.com/help/minimal-reproducible-example) – Ron Apr 13 '23 at 12:48
  • https://stackoverflow.com/questions/32790086/using-a-javascript-function-to-load-a-page-in-an-iframe – Nico Zimmer Apr 13 '23 at 12:51
  • You already seem to have a working link, why to mess with JS too? Please describe your issue more clearly. – Teemu Apr 13 '23 at 12:51
  • ah sorry. the main page with a sidebar is at `http://mywebsite.com/index.html` which inside of this page has an iframe with the gallery page on it, i want to use the url to point to loading a specific page into this iframe if possible – Volt64bolt Apr 13 '23 at 13:09
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 14 '23 at 09:42
  • i put in a request to have it deleted already, i realised its stupid and i just decided to go about it normally – Volt64bolt Apr 14 '23 at 14:30

1 Answers1

0

 function UpdateIFrame() {
        var site = "https://www.google.com/";
        document.getElementById('frame').src = site;
    }
  <a href="gallery.html" onclick="UpdateIFrame()" target="displayframe">Gallery</a>
  <iframe id="frame"></iframe>
Nico Zimmer
  • 325
  • 1
  • 12