如何在点击链接时创建iframe? [英] How to create an iframe on clicking a link?

查看:89
本文介绍了如何在点击链接时创建iframe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,表格内有几个链接.链接之一在td标签内.我想要一种调用iframe的方法,该iframe将在用户单击链接后打开.当iframe弹出时,页面的其余部分将变得无响应,并且一旦用户离开iframe,外部页面就会变得响应.表td是这样的:

I have a web page with several links inside a table. One of the links is inside a td tag . I want a way to invoke an iframe, which will be opened once the user clicks on the link. When the iframe pops up the rest of the page will become un responsive and once the user comes out of the iframe the the outer page becomes responsive. The table td is something is like this :

<td >
<a href="configuration.xml related jsp action">Set the Iframe up</a>
</td>

iframe将由另一个jsp的内容填充.

The iframe will be populated by the contents of another jsp .

我很着急,所以忘了粘贴我尝试过的代码:所以在这里:

EDIT : I was in a hurry, so forgot to paste the code that i tried : So here it is :

<td >
<a href="#">Set the Iframe up</a>
<div id="modalMan" style="display:none;">
<div class="modalsub" >
<p class="close"><a href="#"><img src="cbutton.gif" alt="Close"/></a></p>
<iframe id="myFrame" style="display:none;" height="430" width="675" 
src="myJSP.jsp" >
</iframe>
</div>
</div>
</td>

但是,这造成了一个问题,因为没有关闭图标出现,并且div的一部分即是

This however is creating a problem as close icon is not coming and the part of the div i.e.

   <div id ="modalman">
   <p class>
   <iframe src>

所有内容都保持隐藏状态,并且iframe的外观相似,但是功能都变得混乱了,myjsp的javascript内容也保持隐藏状态.

All remain hidden and an iframe opens with similar look, but the functionalities are all scrambled up, the javascript contents of myjsp remain hidden .

再次很抱歉,我忘了提到我已经尝试过onclick功能,但是由于我的href是这样的,因此可以直接在新的浏览器选项卡中打开jsp在iframe中打开它.

EDIT AGAIN : I am very sorry i forgot to mention that i have tried the onclick functionality, but since my href is like this so it goes and opens the jsp directly in a new browser tab instaed of opening it in an iframe.

 <a href="configuration.xml related jsp action">Set the Iframe up</a>

我该如何实现?请提出一种方法.

How can i achieve this ? Kindly suggest a way .

推荐答案

此处提供了可以执行此操作的非常基本的JavaScript函数.函数参数是希望将iFrame附加到的元素以及它要指向的位置.

Heres a very basic JavaScript function that can do it. Function parameters are the element in which you want the iFrame to be appended to and the location in which you want it to point.

HTML

<a href="#" onclick="setIframe(this,'http://www.stackoverflow.co.uk')" >Set the Iframe up</a>

JavaScript

function setIframe(element,location){
    var theIframe = document.createElement("iframe");
    theIframe.src = location;
   element.appendChild(theIframe);
}

这篇关于如何在点击链接时创建iframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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