Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to add an iframe using jQuery

Tags:

jquery

iframe

I'm trying to add an iframe using jquery this way below, but when I click the link it doesn't happen anything.

<head>

    <script type="text/javascript"
            src='//ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js'></script>

    <script type="text/javascript">

        function fun(){
            $('<iframe />');  // Create an iframe element
            $('<iframe />', {
                name: 'frame1',
                id: 'frame1',
                src: 'http://www.programmingfacts.com'
            }).appendTo('body');

    </script>

    </head>

    <body>

        <a href="#" onclick="fun()">clica</a>

    </body>

</html>
like image 481
ziiweb Avatar asked Dec 02 '22 03:12

ziiweb


1 Answers

Try this:

<html>
    <head>
        <script type="text/javascript" src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js'></script>
        <script type="text/javascript">
            $(document).ready(function() {
                $(".submit").click(function()
                {
                    $('<iframe />');  // Create an iframe element
                    $('<iframe />', {
                        name: 'frame1',
                        id: 'frame1',
                        src: 'http://www.programmingfacts.com'
                    }).appendTo('body');
                });
            });
        </script>
    </head>
    <body>
        <a href="#" class="submit">clica</a>
    </body>
</html>
like image 107
Aaron Newton Avatar answered Dec 04 '22 07:12

Aaron Newton