如何在IFrame中打开URL? [英] How to open a URL in IFrame?

查看:196
本文介绍了如何在IFrame中打开URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JSP创建网页.我希望有一个文本框供用户输入URL.当用户按下go时,我希望使用iframe在该页面本身中打开URL.我一直在尝试但无法做到.

I am trying to create web page using JSP. I want to have a text box for user to enter a URL. When user presses go then i want the URL to open in that page itself using iframe. I have been trying but not being able to do it.

<form method="post" target="test">
<script type="text/javascript">
<!--
window.onload=function() {
   df=document.forms[0];
   df[0].focus();
   df[1].onclick=function() {
if((df[0].value=='''')) {
   alert(''please enter valid link'');
   df.reset();
   df[0].focus();
   return;
 }
location.href=''http://''+df[0].value;
  }
 }

-->
</script>
<div id="container" target="test">
<h1>enter the valid link</h1>
<input type="text"/>
<input type="button" value="OK"/>
</div>
</form>
<iframe src="#" style="border: none;" name="test" id="test" height="50%">
          
</iframe>

推荐答案

在您的window.onload函数中只需替换一行

location.href=''http://''+df[0].value;



document.getElementById("test").contentWindow.document.location.href=''http://''+df[0].value;
In your window.onload function just replace a line

location.href=''http://''+df[0].value;

with

document.getElementById("test").contentWindow.document.location.href=''http://''+df[0].value;


非常感谢.您救了我的命.
thank you so much. You saved my life.


guys please help me with this urgent



请停止这种愚蠢的行为.不,这对我们来说并不紧急.您所做的所有事情都是无法创建一个告诉人们您想要什么的主题.



Please cease this idiocy. No, it''s not urgent to us. All you did was fail to create a subject that told people what you wanted.


这篇关于如何在IFrame中打开URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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