开发者

Changing A URL in a Iframe using a text box

I have a website http://speedie.mobi/emulator4/ and I would like to add a text box where people could add their own url to change what appears in the mobile phone.

It is just using a simple iframe browser.

So by adding their url in the text box it would replac开发者_开发问答e the current url with their url.

Quentin


<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>

--> example <--


Using jQuery,

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜