简体   繁体   English

单击特定按钮后如何在iframe中打开特定的JSP页面

[英]How to open a specific JSP page in iframe on click of a particular button

I am using a javascript function to create aniframe, but its not working. 我正在使用JavaScript函数创建aniframe,但无法正常工作。

I have 4 buttons on the main page (using JSP). 我在主页上有4个按钮(使用JSP)。 I want to open 4 different pages within the same window below that(we can think it as header and footer). 我想在下面的同一窗口中打开4个不同的页面(我们可以将其视为页眉和页脚)。 onClick of any of the 4 buttons(that are in the header part) one respective page should open within the same page (in footer part). 应该在同一页面(在页脚部分)中打开一个相应页面的四个按钮(位于页眉部分)中的任何一个onClick on above (can say as in header part) I have some textboxes and want to keep them on every page. 在上面(可以说是标题部分),我有一些文本框,并希望将其保留在每个页面上。 I am using an iframe . 我正在使用iframe One has the static src ie src="index.jsp" and the "footer" one I want to open a different page as per click . 一个具有静态srcsrc="index.jsp"和一个“页脚”,我想按一下打开另一个页面。

I am using the header iframe as - 我将标题iframe用作-

<iframe id='header_iframe' style="width: 100%; height:250px;" src="index.jsp" name="iframe_main" frameborder="0"></iframe>

I am using javascript function to create iframe, but its not working 我正在使用javascript函数创建iframe,但无法正常工作

as- 如-

function setIframe()
{
   var demo_Iframe = document.createElement("iframe");
   demo_Iframe.src = "http://localhost:8084/project/demo.jsp";
   demo_Iframe.id="demo_Iframe";
   demo_Iframe.width="100%";
   demo_Iframe.height="400px";
   document.appendChild(demo_Iframe);
}

I am calling setIframe() on onclick event of button. 我在按钮的onclick事件上调用setIframe()

Try 尝试

document.getElementsByTagName('body')[0].appendChild(demo_Iframe);

Demo: Fiddle 演示: 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM