2013-10-17 5 views
0

url 매개 변수에 나타나는 특정 URL로 어떻게 리디렉션 할 수 있습니까? 예를 들어자바가 URL의 특정 경로로 리디렉션

:

http://www.mywebsite.com/myfolder/redir.html?path=

후 "="나는에 리디렉션 할 특정 URL을 추가합니다.

결과의 URL은 결국 다음과 같이 표시됩니다

자바 스크립트가 redir.html에 재

http://www.mywebsite.com/myfolder/redir.html?path=http://www.newwebsite.com/

는 '경로'URL을 복사 한 페이지를 리디렉션해야합니다.

감사합니다,

답변

1

당신은 here에서 쿼리 문자열 자바 스크립트 함수를 사용할 수 있습니다

window.location.href = getParameterByName("path"); 

function getParameterByName(name) { 
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); 
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), 
     results = regex.exec(location.search); 
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); 
} 
+0

도움

function get_query_param(name) { name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); } window.onload = function() { if (get_query_param('path') != null) alert(get_query_param('path')); } 

희망을 나를 위해 ... 예를 들면 : http://www.mywebsite.com/myfolder/redir.html?path=http:/ /www.google.com/ Google로 리디렉션하지 마세요. –

0

자바 스크립트 함수를 쿼리 매개 변수 얻을 : 작동하지 여전히

관련 문제