2013-02-28 30 views

回答

0

你可以让你的“浏览”按钮调用的onClick javascript函数或做一个动作提交即

<form action="JavaScript:navigate()">...</form> 

为函数本身,你可以设置一个ID为iframe中设置iframe网址从而可以被javascript用来改变URL的位置。

<script> function navigate(){ window.frames['Iframe'].document.location.href = document.getElementByID('newLink').value; } </script> 

和iframe中做到:

<iframe id="Iframe" src=""></iframe> 

因此,最终的代码应该是这样的。

<html> 
    <head> 
    <title>iFrame</title> 
    <script> 
    function navigate(){ 
window.frames['Iframe'].document.location.href = document.getElementByID('newLink').value; 
}  
</script> 
    </head> 
    <body> 
    <form action="JavaScript:navigate()">URL: <input type="text" id="newLink"> 

 <iframe id="Iframe" src=""></iframe> 


    </body> 
    </html> 
+0

对不起,你能告诉我每一个元素(按钮,形式,帧)单个脚本会是什么? THX – aRandomDeveloper 2013-02-28 01:41:10

+0

我已更正它 – 2013-02-28 02:03:03

+0

我已尝试使用该代码,但iframe无法导航到表单中的网址。 :O thx – aRandomDeveloper 2013-03-28 04:06:18