使用文本框更改Iframe中的URL

时间:2011-02-15 04:51:16

标签: javascript html iframe navigation

我有一个网站http://speedie.mobi/emulator4/,我想添加一个文本框,人们可以添加自己的网址来更改手机中显示的内容。

它只是使用简单的iframe浏览器。

因此,通过在文本框中添加其网址,它会将当前网址替换为其网址。

昆汀

2 个答案:

答案 0 :(得分:2)

使用jQuery,

var url = $('#urltext').value();
$('#targetframe').attr('src',url);>

答案 1 :(得分:2)

<script>
    function goTo() {
        var input = get("box").value,
            frame = get("frame");

        if(input.match(/\bhttp(.)*/)) {
            frame.src = input;
        } else {
            input = "http://" + input;
            frame.src = input;
        }      
    }

    function get(id) {
        return document.getElementById(id);    
    }  
</script>


<input type="text" id="box" value="http://www.example.com" />
<button onClick="goTo();">go</button>

<iframe src="http://www.example.com" frameborder="0" id="frame" width="100%" height="90%"></iframe>

- &GT; example&lt; -