How to Load Iframe in jQuery onload Event

Websolutionstuff | Jun-21-2024 | Categories : Laravel PHP jQuery

Hello, laravel web developers! In this article, we'll see how to load an iframe in jQuery on a load event. In jQuery, we'll load iframe using the onload event. The load event occurs when a specified element has been loaded.

This event works with elements associated with a URL (image, script, frame, iframe), and the window object.

Depending on the browser, the load event may not trigger if the image is cached (Firefox and IE).

jQuery Iframe on Load Event

JQuery Iframe on Load Event

<!DOCTYPE html>
<html>
<head>
    <title>How to Load Iframe in jQuery onload Event - Websolutionstuff</title>
</head>
<body>
    <iframe id="input_iframe" src="test.pdf"></iframe>
  
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function() {
            var iframe = $('#input_iframe');
  
            iframe.on('load', function() {
                info('Iframe content has loaded.');
            });
        });
    </script>
</body>
</html>

 

Example:

<!DOCTYPE html>
<html>
<head>
    <title>Load Video in jQuery on Window Load</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
    <div id="test_video"></div>
  
    <script>
        $(window).on("load", function() {
            $('#test_video').prepend('<iframe src="../file/path" width="680" height="383" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>');
        });
    </script>
</body>
</html>

 


You might also like:

Recommended Post
Featured Post
Laravel 10 Scout Search and Algolia Example
Laravel 10 Scout Search and Al...

Hey everyone! Ever wished your Laravel application could deliver lightning-fast search results? Well, I've got great...

Read More

Feb-21-2024

How To Get Client IP Address In Laravel 10
How To Get Client IP Address I...

In this article, we will see how to get a client's IP address in laravel 10. Here we will learn about retrieving the...

Read More

Apr-07-2023

How To Get Selected Checkbox List Value In Jquery
How To Get Selected Checkbox L...

In this tutorial, I will explain you to how to get the selected checkbox value from a checkbox list in jquery, If y...

Read More

Jun-17-2020

How to Reset MySQL Root User Password on Ubuntu
How to Reset MySQL Root User P...

Hey there! If you've ever found yourself scratching your head over a forgotten MySQL root password on Ubuntu, fear n...

Read More

Jan-26-2024