2012-03-01 2 views
0

index.html 파일에서 프레임을 사용하고 있습니다. 프레임의 모든 페이지에는 페이지가 프레임에 있는지 확인하는 코드가 있고 그렇지 않은 경우 index.html로 리디렉션됩니다.프레임 외부 페이지를 index.htm의 특정 프레임으로 리디렉션

지금. 페이지가 프레임에 있는지 확인하고 index.html로 리디렉션하고 싶을뿐 아니라 index.html의 프레임 중 하나에서 페이지를 열고 싶습니다.

나는 지금의로이 코드와 JS 파일을 내장 한 :

if (top.location == self.location) 
{ 
    top.location = 'index.html' 
} 

당신이 알고 수있는 스크립트가 있습니까?

답변

2

서브 페이지의 코드를 'index.html'에 추가하면됩니다.

if (top.location == self.location) { 
    top.location = 'index.html?' + location.href; 
} 

... 그리고 물음표 후 일부를 확인하는 index.html 페이지, 예를 들면의 다른 자바 스크립트를 넣어 : 그건 그렇고

<script type="text/javascript"> 
window.onload = function() { 
    //check if a query string is given 
    if (location.search && location.search.length > 1 
     && location.search.charAt(0) == "?") { 

     //load the URL to the frame 
     window.frames["myframe"].location.href = location.search.substring(1); 
    } 
} 
</script> 

, 당신은 당신의 대상 프레임을 제공해야 이 같은 이름 :

<frameset ... 
    <frame name="myframe" ... 
+0

나는 그것이 작동 할 수 없습니다 : 그것은 나를 이동 만에 주소 표시 줄에 주소를 변경/:'http://192.168.0.2/csharp%20projects/index.html?http : // 192.168.0.2/csharp % 20projects/sitemap.html' from :'http://192.168.0.2/csha rp % 20projects /' – HelpNeeder

+0

주소를 변경하여로드해야하는 서브 페이지를 프레임 세트 페이지에 알립니다. 나는 주소가 바뀌는 것을 피할 수 없다고 생각합니다. 이것은 많은 사람들이 프레임 셋을 좋아하지 않는 이유입니다. –

+1

흥미로운 답변 : [HTML 프레임을 사용하지 않아야하는 이유는 무엇입니까?] (http://stackoverflow.com/questions/1203068/why-should-i-not-use-html-frames) ;-) –

관련 문제