Two adjacent iframes, where the first one serves as a sidebar containing hyperlinks that, when clicked, will display the corresponding content within the second

What is the most effective approach for HTML with two iframes placed horizontally, where the left one serves as a sidebar containing links that will open other HTML pages on the right iframe upon clicking them?

Something similar to this: https://i.stack.imgur.com/opSni.png

Answer №1

Suppose you have full control over all the content, or at least control over the menu. In that case, you can achieve this by utilizing the postMessage function.

  1. The script in the menu iframe sends a message to the parent HTML page (window.top) when a link is clicked,
  2. The script in the parent page receives the message and extracts the desired URL from the message's data property,
  3. The parent page script modifies the iframe's src attribute with the desired URL.

However, regarding best practices, there isn't a specific one for the use case you described. It is generally recommended to avoid it if possible.

To put it simply, iframes add unnecessary complications and are best avoided. They often result in limitations and problems down the line. A more detailed explanation supporting this notion can be found here: Why the Iframe is Evil.

Since all your content resides on the same server, I suggest considering AJAX practices to load the content directly into the HTML page. This approach offers several advantages:

  • The loaded content will inherit the same CSS as the parent page,
  • The loaded content can be manipulated using the same JavaScript as the parent page,
  • The container div will automatically resize to fit the content, reducing the number of scrollbars on the page,
  • You won't need to learn complex mechanisms like postMessage unless you really require or desire them.

An easy way to experiment with this idea is by using jQuery and its load() function. I have created a codepen example that demonstrates the code you can try on your project. Note that it won't work in codepen as the code window is at s.codepen.io and the linked pages are in codepen.io. Due to the access-control-allow-origin policy, the browser prevents loading anything.

http://codepen.io/daveycakes/pen/MbOmEB

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The symbols ">>" have been changed to "�"

There has been a report from one of our application users stating that they are seeing the character � instead of >> on their home and other pages. This issue is only affecting one out of 100 users, and the user in question is using IE11. What could ...

Tips for incorporating external routes into the routes index file

I am currently dealing with a users.js and an index.js file. users.js const express = require('express'); const router = express.Router(); const {catchErrors} = require('../handlers/errorHandlers'); const authController = require(&ap ...

What steps can be taken to enable users to draw a path on a Google Map?

I'm working on a new project for a Facebook app that will allow users to map out their marathon route using Google Maps. I plan to utilize mySQL database records to store fixed points along the path (such as specific locations based on latitude and lo ...

Obtain details regarding a worker's collision

This code snippet is being used to manage cluster crashes within a node application cluster.on('exit', function (worker, code, signal) { console.log("error in cluster",worker); console.log("cluster code",code); console.l ...

"Triggering ngClick causes ngSrc to update, however, the keydown event handler does not have

Currently, I am developing a dynamic live map application that includes various navigation buttons like pan and zoom. To enable keyboard control, I have implemented a keydown event handler that triggers the same function as the button clicks. Interestingl ...

Obtaining HTML content using Java

I received my personal data download from Facebook and decided to have some fun with it. I'm currently trying to isolate a specific group chat that I am a part of. The file size I am working with is 18 kB, filled with HTML code within tags but lackin ...

Troubleshooting a problem with CSS animations disappearing

I've been experimenting with CSS animations and I've run into a bit of a snag. I'm looking to create a div that fades in with a delay - meaning it won't be visible until the animation starts. Here's what I have so far: http://jsfi ...

Processing incoming requests with a loading interface in CodeIgniter

Is there a way to notify the user who sent the request whether or not the requested user will approve it? Optional: If there is no notification sent to the user who made the request, the requested user will have to wait for verification. For Example: Ima ...

The bond between TypeORM and express

I am working on establishing Many-to-One and One-to-Many relationships using TypeORM and MySQL with Express. The database consists of two tables: post and user. Each user can have multiple posts, while each post belongs to only one user. I want to utilize ...

The most effective method for positioning a child element to the left and top using Flexbox grid

I am currently working on visualizing queues and processes within a system. Each process is associated with a specific queue from which it retrieves data. I aim to create a layout similar to the following: https://i.stack.imgur.com/BXyts.png However, I a ...

Is it possible to update labels on an AngularJS slider using a timeout function?

I recently started implementing an AngularJS slider to navigate through various date and time points. Specifically, I am utilizing the draggable range feature demonstrated in this example - https://jsfiddle.net/ValentinH/954eve2L/ The backend provides the ...

Issue: Invalid element type detected: expected a string (for built-in components) or a class/function

Currently, I am in the process of learning how to make API calls using React Redux. I decided to practice by implementing an example in StackBlitz. However, I encountered an error after selecting a channel and clicking on the 'Top News' button. C ...

Implementing real-time style changes with Angular 6 through Environment Variables

Attempting to dynamically change styles in Angular 6 using environment variables has been a success for me. Here is how my file structure is organized: src -app -assets -environments -scss -theme1.scss -theme2.scss -_variables.scss -styles.sc ...

I'm encountering an issue with my array in JavaScript while using // @ts-check in VS Code. Why am I receiving an error stating that property 'find' does not exist on my array? (typescript 2.7

** update console.log(Array.isArray(primaryNumberFemales)); // true and I export it with: export { primaryNumberFemales, }; ** end update I possess an array (which is indeed a type of object) that is structured in the following manner: const primar ...

Using Javascript and jQuery to create an infinite animated background change with fade effect

I am struggling to figure out how to automatically change the background of a div every 3 seconds, looping through a series of images. I posted about this issue before but didn't receive much help. function animate() { change1(); change2() ...

Vue: Displayed list displaying checked checkboxes

My attempt at displaying the selected checkboxes is as follows: <pre>{{ JSON.stringify(selectedAttributes, null, 2) }}</pre> <ul class="list-unstyled" v-for="category in categories" ...

Can you identify the HTML table format and suggest effective web scraping methods?

I have been attempting to retrieve data from the following link, http://www.rchsd.org/doctors/index.htm? strt = 0 & ln = & fn = & sp = & grp = & loc = & lng = & gen = , using R but finding it quite challenging. I have observed that the URL remains constan ...

What is the best approach for resolving this asynchronous task sequencing issue in JavaScript?

Below is a code snippet where tasks are defined as an object and the function definition should ensure the expected output is met. Let tasks = { ‘a’: { job: function(finish){ setTimeout(() => { ...

jQuery Mobile panel buttons are functioning properly within a maximum width of 300 pixels

I have constructed a panel that adjusts its size based on the device's screen using responsive design techniques. The code for this panel is as follows: <div data-role="panel" data-position="right" data-display="overlay" data-theme="a" id="add-for ...

What is the most efficient way to convert an entire HTML page into a different language using Django?

As I work on building a website with Django framework, I am faced with the task of translating my web page into French while keeping all other pages in English. <html lang="fr"> Despite setting the code as shown above, I am encountering issues wher ...