Search code examples
urliframenoscript

Is it possible to keep track of iFrame src in main url without js?


The project contains an <iframe> on the left which displays links to files in different ways (order of include, inheritance, and filepath styles) and an <iframe> on the right which displays the selected file.

What I'm trying to do is make it so the url (top) reflects what should be shown in both of these iframes, so copy pasting the url will result in the same view. I could do it easily with js, but I'm trying to do without.

Is it possible to modify the main url in a way that reflects the state of these iframes without js?

top: address bar; left: index; right: iframe


Solution

  • No, there is no such mechanism in pure HTML.

    You could make this work with some server-side processing – make the links actually redirect the user to a different page, then the server processes the URL query string to know what to display in which part of the page.

    Or you could use JavaScript, and use the # part of the URL to store the current location.

    There is potentially another way to do it now, with CSS3, although this would be extremely tedious (IMHO), and would also mean your entire website is contained and served in one single file. CSS has a :target selector which would match e.g. <a name="foo"> when #foo was in the URL. Using this you could wrap parts of the page in "targetted" blocks, which would only display when they are needed.

    Note that all three of these solutions basically replace your <iframe>s completely.