我正在尝试复制此网站的脚本功能:http://responsinator.com/
我们的想法是从表单中获取URL并插入一个或多个iFrame。
抱歉,我有点像菜鸟。我觉得这很简单,但我被卡住了。这是我到目前为止的地方:
function handleButtonEnterClick() {
var textbox_value = document.getElementById("url_textbox").value;
document.getElementById('myUrl').value = window.location;
var form = document.getElementById('myForm');
form.action = textbox_value;
form.submit();
}
<div id="container">
<form action="" method="post" id="myForm">
<p>Enter URL:</p>
<input type="hidden" id="myUrl" name="url" />
<input type="text" id="url_textbox" name="url_textbox" />
<input type="button" id="button_enter" name="button_enter"
value="enter" onclick="handleButtonEnter" />
</form>
</div>
谢谢!
答案 0 :(得分:1)
喜欢这个? http://jsfiddle.net/xtpD5/1/
您只需通过target属性将表单提交到iframe即可。它会在iframe中打开它
function handleClick() {
var url = document.getElementById('url_textbox').value;
document.getElementById('myForm').action = url;
return true;
}
<div id="container">
<form action="" method="post" id="myForm" target='iframe'>
<p>Enter URL:</p>
<input type="hidden" id="myUrl" name="url" />
<input type="text" id="url_textbox" name="url_textbox" />
<input id="button_enter" name="button_enter" value="enter" type="submit" />
</form>
</div>
<iframe name="iframe"></iframe>