2013-12-11 2 views
1

네 개의 링크가있는 navbar가 있습니다. 각 페이지가 navbar 아래의 프레임에서 열리 며 링크를 클릭합니다.하지만 새 탭에서 마우스 오른쪽 버튼을 클릭하면 전체 페이지가 표시됩니다. 열린 상태 즉, 새 탭에서 특정 링크 만 열면 안됩니다.JSP 페이지에서 <iframe>을 관리합니다

링크는 프레임에서 열거 나 별도로 표시하지 말아야합니다. 이 일을 할 수 있습니까?

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

링크를 마우스 오른쪽 버튼으로 클릭하고 새 창에서 열면 전체 응용 프로그램이 다시 시작됩니다.

답변

0

iframe (page1.jsp, page2.jsp 및 page3.jsp)에만 표시되어야하는 각 페이지에는 자체 창에 표시되는지 여부를 감지하는 JS가 있어야합니다. 당신이 표시된 프레임 소스를로드하는 당신은 iframe의 SRC를 야기한다 index.jsp를 내부, 그리고

<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> 

: iframe이있는 페이지가 index.jsp를 경우 예를 들어, page1.jsp이 코드를 포함해야한다 :

<% 
// 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> 
+0

슈퍼 슈퍼 슈퍼! 감사 –

관련 문제