javascript - Managing <iframe> in a jsp page - Stack Overflow

i have a navbar which has four link , onclick any link the respective page opens up in a frame below th

i have a navbar which has four link , onclick any link the respective page opens up in a frame below the navbar, but when i use right click open in new tab i want the entire page to be opened ie opening a particular link alone in a new tab should not be allowed

Links should be opened or displayed in the frame alone and not separately. can this be done ?

 <a href="page1.jsp" target="frame1">page1</a>
 <a href="page2.jsp" target="frame1">page2</a>
 <iframe name="frame1" src="page3.jsp">

right clicking on the link and opening in new window should launch the entire application again.

i have a navbar which has four link , onclick any link the respective page opens up in a frame below the navbar, but when i use right click open in new tab i want the entire page to be opened ie opening a particular link alone in a new tab should not be allowed

Links should be opened or displayed in the frame alone and not separately. can this be done ?

 <a href="page1.jsp" target="frame1">page1</a>
 <a href="page2.jsp" target="frame1">page2</a>
 <iframe name="frame1" src="page3.jsp">

right clicking on the link and opening in new window should launch the entire application again.

Share Improve this question edited Dec 11, 2013 at 15:16 Ragesh Kr asked Dec 11, 2013 at 15:03 Ragesh KrRagesh Kr 1,7339 gold badges32 silver badges48 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 0

Each page that should only be shown in the iframe (page1.jsp, page2.jsp, and page3.jsp) should include JS to detect whether or not it's being displayed in its own window. For example, if the page with the iframe is index.jsp, page1.jsp should include this code:

<script type="text/javascript">
<!--
if (top.location.href == self.location.href)
  // Redirect user to main page, passing current page name:
  top.location.href = 'index.jsp?frame=page1';
//-->
</script>

Then, inside index.jsp you should cause the src of your iframe to load the indicated frame source:

<% 
// Establish default source:
String frame_src = 'page3.jsp';
// Establish controlled list of pages to show in the iframe (important to be restrictive)
String[] allowed_srcs = ['page1','page2','page3'];
// Get targeted frame from query string, if given:
String targeted_frame = request.getParameter('frame');
if(Arrays.asList(allowed_srcs).contains(targeted_frame))
  frame_src = targeted_frame + '.jsp';
%>
<iframe name="frame1" src="<%= frame_src %>"></iframe>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744589489a4582514.html

相关推荐

  • javascript - Managing &lt;iframe&gt; in a jsp page - Stack Overflow

    i have a navbar which has four link , onclick any link the respective page opens up in a frame below th

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信