The Wayback Machine - https://web.archive.org/web/20241001111552/https://www.geeksforgeeks.org/how-to-update-two-frames-at-the-same-time-using-html/
Open In App

How to update two frames at the same time using HTML ?

Last Updated : 06 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In this article, We are going to see how you can update two frames at the same time. 

Approach: We take two iframes with unique id names i.e. “frame1” and “frame2” both align to the center of our page and a button. When we click the button then the URLs of the iframes is replaced with other URLs.

HTML Code: In this code, we attach one event listener to the button. When we click the button, the content of the body should be changed to the URLs of two iframes simultaneously at a time by using the src attribute of both iframes.

Example: In this example, we are using the above approach.

HTML
<!DOCTYPE html>
<html>

<head>
    <title> update two frames at the same time</title>
</head>

<body>
    <h1 style="display:flex;
        justify-content:center;color:green;">
        GeeksforGeeks
    </h1>

    <div style="padding:10px;border:2px solid green;">

        <div style="display:flex;flex-wrap:wrap;
            justify-content:center;">
            <iframe src="https://www.youtube.com/embed/aMn7sO1d4Yc" id="frame1">
            </iframe>
            <div style="width:10px;">
            </div>
            <iframe src="https://www.youtube.com/embed/8Pv96bvBJL4" id="frame2">
            </iframe>
        </div>
        <button style="margin-left:50%;margin-right:30%;
            margin-top:10px;" id="update">
            Click me
        </button>
    </div>

    <script>
        document.getElementById('update')
            .addEventListener('click', function () {

                // Change src attribute of iframes at a same time
                document.getElementById('frame1').src =
                    'https://www.youtube.com/embed/QS8xU4TqnQE';
                document.getElementById('frame2').src =
                    'https://www.youtube.com/embed/3w0XfBU2ufw';
            });
    </script>
</body>

</html>

Output:

Note: We can update the content of the frame with <a> tag with the target attribute. The URL that we want to open inside the iframe will replace the URL of the iframe previously present. We click “clickme” link, the “b.html” is replaced with “a.html”.



Similar Reads

How to divide an HTML page into four parts using frames ?
This article shows how to divide a page into four parts using HTML frames. This can be used to represent the header, sidebar, footer, and main content. The frames are created using the <frame> tag. We will have to use four HTML files for each of the portions. Syntax<frameset> // frame elements</frameset>Example 1: This example wil
2 min read
HTML DOM Window frames Properties
The HTML DOM Window frames property in HTML DOM is used to return the frame element in the form of an array object. This property represents all <iframe> elements in the current window. DOM Windowframe is a read-only property. Syntax: window.frames Properties: length property: It returns the number of iframe elements in the current window. lo
2 min read
p5.js | frames() Function
The frames() function is an inbuilt function in p5.js library. This function is used to return the no of frames. There was a simple equation between samplesRate, duration, and frames. The equation is frames = samplesRate*duration. Syntax: frames() Note: All the sound-related functions only work when the sound library is included in the head section
1 min read
How to create frames ?
The task is to create frames using HTML. HTML is HyperText Markup Language, and it is the standard markup language for creating web pages. It describes the shape of a web page and includes a sequence of elements. Frames in HTML are used to divide your browser window into more than one section in which every phase can load a separate HTML report and
2 min read
How to open URL in same window and same tab using JavaScript ?
Opening a URL in the same window and in the same tab is a common requirement for web developers. This functionality is useful when you want to load a new web page or document into the current browser window and replace the content of the current web page. There are several ways to open URLs in the same window and in the same tab using JavaScript: T
4 min read
How to add/update an attribute to an HTML element using JavaScript?
To add/update an attribute to an HTML element using JavaScript, we have multiple approaches. In this article, we are going to learn how to add/update an attribute to an HTML element using JavaScript. Below are the approaches used to add/update an attribute to an HTML element using JavaScript: Table of Content Using setAttribute() MethodUsing HTML D
2 min read
How to run two PHP versions for two projects on same apache server ?
In this article, we will learn about running two versions of PHP on the same Apache server. To manage many domains, the Apache webserver uses virtual hosts on a single instance. Prerequisite: We will be using the XAMPP server to use the Apache server and some knowledge to use it. First, download the older version of XAMPP that can be of any version
2 min read
What is the best way to compare two HTML pages with same data but different markup?
In this article, we will be learning about the best way to compare two HTML pages with the same data but different markup. At first, we need to know how to compare two HTML pages. Now, the most efficient way to check both the pages is to use the hash code of both the page contents and compare it for equality. JavaScript hashCode(): In order to impl
4 min read
How to convert UTC date time into local date time using JavaScript ?
Given an UTC date and the task is to convert UTC date time into local date-time using JavaScript toLocaleString() function. Syntax: var theDate = new Date(Date.parse('DATE_IN_UTC')) theDate.toLocaleString() Example 1: This example converts UTC date time into local date time using JavaScript. C/C++ Code <body> <h1 style="color:green;
1 min read
How to use both Tailwind CSS and Bootstrap 4 at the same time ?
In this article, we will know how to use Bootstrap with Tailwind CSS, at a moment, in the same code. We can use both the CSS frameworks together but it is not recommended. Because few classes will contradict with each other like "container", "clearfix", etc. As we know that Bootstrap is a known CSS framework. Although the Tailwind CSS framework can
2 min read
How to send Multiple Requests at same time in Postman ?
Postman is a popular API development tool that allows us to design, test, document, and debug APIs more efficiently. This article is all about sending multiple requests at the same time in Postman. Advantages of sending multiple requests at same time in Postman :Efficiency: It saves time and improves efficiency.Parallel Testing: Postman allows you
1 min read
How to Toggle the Buttons & Submit a Form at the Same Time ?
In web development, it is common to come across situations where you need to toggle buttons and submit a form simultaneously This functionality is useful for users to interact with the form by enabling or disabling buttons while processing or submitting form data and integrating a button toggle with the form submission you can enhance the user expe
2 min read
How to place two div side-by-side of the same height using CSS?
The two or more different div of same height can be put side-by-side using CSS. Use CSS property to set the height and width of div and use display property to place div in side-by-side format. The used display property are listed below: display:table; This property is used for elements (div) which behaves like table.display:table-cell; This proper
2 min read
How to check two elements are same using jQuery/JavaScript ?
Given an HTML document containing two elements and the task is to check whether both elements are same or not with the help of JavaScript. Approach 1: Use is() method to check both selected elements are same or not. It takes an element as argument and check if it is equal to the other element. Example: This example implements the above approach. C/
2 min read
How to check two objects have same data using JavaScript ?
In JavaScript, we cannot directly compare two objects by equality operators (double equals == or triple equals ===) to see whether they are equal or not. Comparing two objects like this results in false even if they have the same data. It is because those are two different object instances, they are referring to two different objects. There is no d
2 min read
How to create three boxes in the same div using HTML and CSS ?
We can place three or more different divs side by side in the same div using CSS. You can achieve this using Flexbox, but you need to use wrapper divs and apply different flex directions to each of them to make the grid layout work. You can set the height and width of the div by using CSS properties. Syntax:flex: flex-grow flex-shrink flex-basis |
3 min read
How to directly update a field by using ng-click in AngularJS ?
In this article, we will see how to update the field directly with the help of the ng-click directive in AngularJS, along with understanding different ways to implement it through the implementations. Any field can be updated with ng-click using a custom JavaScript function. For this, we can make a clickable object in HTML (usually a button) and at
3 min read
How to set or update page title using UI-Router?
UI-Router: UI-Router is a client-side router. It is made for single-page web applications. A client-side router updates the browser URL as the user navigates through the single-page app. AngularJS allows you to change your page title at different stages Let's see how to change title using a resolve function in our $state to tell the title using $ro
2 min read
How to update the state of react components using callback?
The state is mutable in react components. To make the React applications interactive we almost use state in every react component. The state is initialized with some value and based on user interaction with the application we update the state of the component at some point in time using setState method. setState method allows to change of the state
3 min read
How to change/update image size dynamically using amp-bind in Google AMP ?
Sometimes you want to add custom interactivity to your AMP pages to make your pages look more user-friendly and user calling. Although AMP's pre-built components are limited, so amp-bind is made to overcome this problem. It helps the developer to add custom interactivity to the pages without using AMP's pre-built components. You can use amp-bind to
2 min read
How to change/update CSS class dynamically using amp-bind in Google AMP ?
Sometimes you want to add custom interactivity to your AMP pages to make your pages look more user-friendly and user calling. Although AMP's pre-built components are limited, so amp-bind is made to overcome this problem. It helps the developer to add custom interactivity to the pages without using AMP's pre-built components. You can use amp-bind to
3 min read
How to change/update text dynamically using amp-bind in Google AMP ?
Sometimes you want to add custom interactivity to your AMP pages to make your pages look more user-friendly and user calling. Although AMP's pre-built components are limited, so amp-bind is made to overcome this problem. It helps the developer to add custom interactivity to the pages without using AMP's pre-built components. You can use amp-bind to
2 min read
How to change/update image dynamically using amp-bind in Google AMP ?
Sometimes you want to add custom interactivity to your AMP pages to make your pages look more user-friendly and user calling. Although AMP's pre-built components are limited, so amp-bind is made to overcome this problem. It helps the developer to add custom interactivity to the pages without using AMP's pre-built components. You can use amp-bind to
3 min read
How to update single and multiple documents in MongoDB using Node.js ?
MongoDB the most popular NoSQL database, is an open-source document-oriented database. The term ‘NoSQL’ means ‘non-relational’. It means that MongoDB isn’t based on the table-like relational database structure but provides an altogether different mechanism for storage and retrieval of data. This format of storage is called BSON (similar to JSON for
2 min read
How to update record in Cassandra using ExpressJS ?
Apache Cassandra is a free and open-source, distributed, highly scalable, wide column store, NoSQL database management system. it is designed to handle large volumes of data, providing high availability with no single point of failure. This article shows you that how to use Cassandra using express js and also shows how to update record in Cassandra
6 min read
Covid-19 cases update using Cheerio Library
In this article we are going to learn about that how can we get the common information from the covid website i.e Total Cases, Recovered, and Deaths using the concept of scraping with help of JavaScript Library. Library Requirements and installation: There are two libraries that are required to scrap(or get the required information from the website
3 min read
How to Update Properties of Pseudo Element :after and :before using Javascript ?
In this article, we will learn how to select and update the CSS properties of pseudo-elements ::after and ::before using JavaScript. The HTML elements like <div>, <h1>, <p>, etc. can be easily selected using document.getElementById() and other related JavaScript methods, selecting pseudo-elements using JavaScript requires a slight
4 min read
How to Update Data in MySQL Database Table Using PHP?
Updating data in a MySQL database table using PHP is a fundamental aspect of web development, particularly in applications where user interactions involve modifying existing records. This guide delves into the process of updating data in a MySQL database table using PHP, covering database connection, SQL queries, error handling, and best practices.
3 min read
How to Update Data in JSON File using JavaScript ?
JSON stands for JavaScript Object Notation. It is a text-based data exchange format that allows you to transfer data between different languages and platforms. JavaScript is commonly used to interact with JSON files. Updating data in a JSON file involves reading the file and then making the necessary changes to the JSON object and then writing the
4 min read
How to Update a Document in MongoDB using NodeJS?
Updating documents in MongoDB is a basic operation for maintaining and managing your database effectively. Node.js, combined with MongoDB, offers a powerful and flexible environment for performing database operations. In this article we will learn how to update a document from a MongoDB collection, starting from connecting the MongoDB to NodeJS, cr
4 min read