All I want 웹 사이트 url 을 가져올 수 있다. Url 링크를 통해 조롱했기 않고 있다. 내가 할 수 있는 페이지의 url 을 잡기 위한 로드중 전체, 즉 현재 웹 사이트 및 as I .하십시오. 함께 할 변수로
JavaScript 다양한 방법을 사용하면, 이는 현재 읽어들이려면 및 변경하십시오 표시되려면 browser& # 39 의 URL 주소 표시줄에는. 이 모든 방법은 '위치' 는 '창' 의 속성을 사용하여 객체에는 객체에는. 현재 위치에 있는 객체를 생성할 수 있습니다 '새' uirl 다음과 같습니다.
var currentLocation = window.location;
<protocol>//<hostname>:<port>/<pathname><search><hash>
이런 '위치' 이 모든 object properties 액세스하려면 그들이 uirl 구성 요소 또는 반품하십시오 설정할 수 있습니다.
대답을 잡을라는데 바래요.
'사용' 을 읽기 및 쓰기 액세스하려면 빈다우드로카션 [장소 객체에는] (https://developer.mozilla.org/En/DOM/Window.location # Location_object) 는 현재 프레임의 연관됨. 내려받습니다 주소를 싶은 경우 읽기 전용으로 사용할 수 있습니다 '하는 것과 같은 값을 컨테인먼트하는 문자열이어야 도쿠망스로우', '빈다우드로카션.흐레프'.
, 현재 페이지 url 을 쉽게 확인 받고 있는 전체 순결케 사용하여 JavaScript. 예를 들어, 이 코드를 시도하시겠습니까 여기있을 페이지:
window.location.href;
// use it in the console of this page will return
// http://stackoverflow.com/questions/1034621/get-current-url-in-web-browser"
>. 이 '속성' 빈다우드로카션.흐레프 되돌려줍니다 현재 페이지의 url 을.
<! - begin 스니핏: js 숨기십시오: 거짓값 콘솔: 진정한 바벨. > 거짓값 -;
document.getElementById("root").innerHTML = "The full URL of this page is:<br>" + window.location.href;
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript</h2>
<h3>The window.location.href</h3>
<p id="root"></p>
</body>
</html>
끝 - < 스니핏 >;!
나쁜 건 아니지만 하라님의 이 잘 알려져 있다.
상대 경로를 사용하여 간단히 빈다우드로카션드패스나미 ',' 하는 경우,
만약 you& # 39 와 같은 호스트 이름을 얻기 위해 사용할 수 있습니다 ',' 빈다우드로카시옹스트로스나미; d
및 사용 할 경우 별도로 포로토콜 내려받습니다 빈다우드로카션.프로토콜 ','
또한 페이지에는 '태그' 해시라고 경우, 다음과 같은 이해했소 수 있습니다. '빈다우드로카션.하시'.
그래서 '올인' 한 번 빈다우드로카션.흐레프 처리합니다. 기본적으로:
window.location.protocol + '//' + window.location.hostname + window.location.pathname + window.location.hash === window.location.href;
//true
또한 '윈도' 에서 이미 내시경이요 창을 사용하는 경우 필요 없습니다.
따라서 이 경우, 사용할 수 있습니다.
location.protocol
location.hostname
location.pathname
location.hash
location.href
<! - begin 스니핏: js 숨기십시오: 거짓값 콘솔: 진정한 바벨. > 거짓값 -;
console.log('document.location', document.location.href);
console.log('location.pathname', window.location.pathname); // Returns path only
console.log('location.href', window.location.href); // Returns full URL
끝 - < 스니핏 >;!
내려받습니다 해시 태그를 사용하여 위치 현재 URL 수 있습니다 사용하여:
// Using href
var URL = window.location.href;
// Using path
var URL = window.location.pathname;
$(location).attr('href');
>. 빈다우드로카션.
Location {href: "https://stackoverflow.com/questions/1034621/get-the-current-url-with-javascript",
ancestorOrigins: DOMStringList,
origin: "https://stackoverflow.com",
replace: ƒ, assign: ƒ, …}
>. 도쿠망.로카션
Location {href: "https://stackoverflow.com/questions/1034621/get-the-current-url-with-javascript",
ancestorOrigins: DOMStringList,
origin: "https://stackoverflow.com",
replace: ƒ, assign: ƒ
, …}
>. 빈다우드로카션드패스나미
"/questions/1034621/get-the-current-url-with-javascript"
>. 빈다우드로카션.흐레프
"https://stackoverflow.com/questions/1034621/get-the-current-url-with-javascript"
>. 로카시옹스트로스나미
"stackoverflow.com"
현재 URL 을 사용하여 패스 '에서' 페이지콘테스트롬리퀘스트스콘티스타파스 이스트 액세스할 수 있습니다. Ajax 호출 할 수 있는 스케쳐내 다음 URL 을 사용합니다.
url = "${pageContext.request.contextPath}" + "/controller/path"
예: 'Http://stackoverflow.com/posts/36577223' 이 페이지의 부여하느뇨 'http://stackoverflow.com/controller/path'.
>. - 빈다우드로카시옹스트로스링 (); >. >. - 빈다우드로카션.흐레프
$(".disapprove").click(function(){
var id = $(this).attr("id");
$.ajax({
url: "<?php echo base_url('index.php/sample/page/"+id+"')?>",
type: "post",
success:function()
{
alert("The Request has been Disapproved");
window.location.replace("http://localhost/sample/page/"+id+"");
}
});
});
여기 지금 사용하고 있는 id 와 ajax 를 사용하여 페이지를 제출됩니다 리디렉션하십시오 window.location.replace * 특성은 'id = ", " 추가하기만,' 이다.