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 badges1 Answer
Reset to default 0Each 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>