반응형
jQuery를 사용하여 URL로 이동하는 방법
jQuery 또는 JavaScript를 사용하여 URL로 이동하는 방법
<a href="javascript:void(0)" onclick="javascript:goToURL()">Go To URL</a>
function goToURL(url){
// some code to go to url
}
팝업에서 이 링크를 호출하고 싶기 때문에 window.location을 사용하지 않습니다.
새 링크도 팝업으로 열립니다.나도 에이잭스를 쓰고 싶지 않아.JavaScript에서 href를 시뮬레이트하기만 하면 됩니다.
//As an HTTP redirect (back button will not work )
window.location.replace("http://www.google.com");
//like if you click on a link (it will be saved in the session history,
//so the back button will work as expected)
window.location.href = "http://www.google.com";
왜 사용하지 않는가?
location.href='http://www.example.com';
<!DOCTYPE html>
<html>
<head>
<script>
function goToURL() {
location.href = 'http://google.it';
}
</script>
</head>
<body>
<a href="javascript:void(0)" onclick="goToURL(); return false;">Go To URL</a>
</body>
</html>
window.location이 바로 당신에게 필요한 것입니다.다른 방법은 앵커 요소를 만들고 클릭을 시뮬레이션하는 것입니다.
$("<a href='your url'></a>").click();
사실 이걸 가지고 놀려면 앵커 넘버를 사용해야 해요.Gmail URL 시스템을 리버스 엔지니어링하면
https://mail.google.com/mail/u/0/#inbox
https://mail.google.com/mail/u/0/#inbox?compose=new
# 뒤의 모든 것은 페이지에 로드하고 싶은 부분입니다.그러면 로드 장소를 선택하면 됩니다.
참고로 #something을 추가하여 document.location을 사용해도 페이지가 갱신되지 않습니다.
언급URL : https://stackoverflow.com/questions/16959476/how-to-go-to-a-url-using-jquery
반응형
'programing' 카테고리의 다른 글
file_get_contents() UTF-8 문자를 분할합니다. (0) | 2022.09.28 |
---|---|
오브젝트 메모리주소에의 액세스 (0) | 2022.09.28 |
MariaDB 생성 뷰가 SELECT를 다른(잘못된) 쿼리로 변경합니다. (0) | 2022.09.28 |
Node.js의 안전한 랜덤 토큰 (0) | 2022.09.28 |
빈 배열 요소 제거 (0) | 2022.09.28 |