如何使用jQuery重新加载iframe [英] How To Reload A iframe Using jQuery

查看:179
本文介绍了如何使用jQuery重新加载iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用iframe在浏览器窗口中创建了一个基本浏览器:

I've created a basic browser within a browser window using an iframe:

目的是允许使用jquery鼠标悬停样式,即/突出显示全部链接红色等...更改字体等..

The purpose is to allow mouse-over styling of elements using jquery ie/ highlight all links red etc... change font etc..

我创建了两个文件:

browser.php

<html>
    <head>
        <title></title>

        <style>

        #netframe {
            float:right; 
            height: 100%; 
            width: 80%;
        }

        #sidebar {
            float:left; 
            height: 100%; 
            width: 20%;
        }

        </style>



    </head>
    <body>


    <div id="container">

        <div id="sidebar">

    Enter A URL:
            <input type="text" name="url" id="url">
            <input type="button" value="load" id="load">

            <br><br>    


        </div>

        <div id="netframe">
            <iframe height="100%" width="100%" class="netframe" src="pullsite.php" id="main_frame"></iframe>
        </div>

    </div>


    </body>
</html>

pullsite.php

<html>

<head>

    <title></title>

    <link href="css/reset.css" rel="stylesheet" type="text/css">

    <style>
        .highlight { 
            outline-color: -moz-use-text-color !important;
            outline-style: dashed !important;
            outline-width: 2px !important;
        }
    </style>    

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>



</head>

    <body>

    <div id="contents">           

    <?php echo file_get_contents('http://www.google.com/webhp?hl=en&tab=iw'); ?>

    </div>

        <script>

        $("#contents").contents().find("a").addClass("highlight");

        </script>


    </body>


</html>

有人可以帮助我使用的jquery代码允许用户输入新的URL输入字段并重新加载iframe。

Can someone please help with the jquery code I could use allow a user to enter a new url in the input field and reload the iframe.

谢谢!!!

推荐答案

HTML排序:

<input type="text" name="url" id="url"/>
<input type="submit" name="go" id="go" value="Go!"/>
<iframe id="miniBrowser"></iframe>

jQuery:

$('#go').on('click', function() {
  $('#miniBrowser').attr('src', $('#url').val());
});

这篇关于如何使用jQuery重新加载iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆