2014-05-12 3 views
0

시작 페이지에서 다른 페이지로 리디렉션하려고합니다. 나는이 코드를 가지고 있지만 사이트의 모든 페이지가 아닌 사용자가 도착한 첫 페이지 (홈페이지)에서만 활성화되도록하고 싶습니다. 특정 페이지에서만 페이지 리디렉션

내가 사용하고 코드이지만 모든 페이지에 실행에 유지 :

var url ='http://cargocollective.com/clairelefevre/about'; 
var delay = 6; 
var d = delay * 1000; 
window.setTimeout ('parent.location.replace(url)', d); 

감사합니다, 마탄을

당신은 그래서 리퍼러, 확인할 수 있습니다
+0

코드 한 장만 입력하면됩니다. – gonzofish

답변

1

parent.location 값을 테스트 할 수 있습니다.

if(parent.location == 'http://cargocollective.com/') 
{ 
    var url ='http://cargocollective.com/clairelefevre/about'; 
    var delay = 6; 
    var d = delay * 1000; 
    window.setTimeout ('parent.location.replace(url)', d); 
} 

솔직히 말해서, 그것은 매우 깨끗한 IMO가 아닙니다. 내가 할 일은 ID와 값을 사용하여 홈페이지에 숨겨진 입력을 넣는 것입니다. 이 입력을 테스트하여 사용자가 홈페이지에 있는지 테스트하십시오.

location.pathname 값을 확인할 수도 있습니다.

if(parent.location.pathname == '/') 
{ 
    //your code 
} 
+0

감사합니다 !! 그것을 해결! –

0

:

if (document.referrer.indexOf(window.location.origin) == -1) { 
    window.setTimeout ('parent.location.replace(url)', d); 
} 
0
마음에 와서이 문제를 해결
var currUrl = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname; 
var homeUrl = "http://cargocollective.com/"; 
if (currUrl == homeUrl) { 
    var url ='http://cargocollective.com/clairelefevre/about'; 
    var delay = 6; 
    var d = delay * 1000; 
    window.setTimeout ('parent.location.replace(url)', d); 
} 
0

두 가지 방법.

  1. 만 스크립트 태그 내부의 홈 페이지에 코드를 삽입 :

    <script>

    var url ='http://cargocollective.com/clairelefevre/about'; 
    var delay = 6; 
    window.setTimeout ('parent.location.replace(url)', delay * 1000); 
    

    </script>

  2. 테스트 페이지의 위치는 if 문에 올 리디렉션하기 전에

    if (window.location.pathname === '/') { 
        var url ='http://cargocollective.com/clairelefevre/about'; 
        var delay = 6; 
        window.setTimeout ('parent.location.replace(url)', d * 1000); 
    } 
    
관련 문제