div가 하나 있는데, 안에는 a가 있습니다. div를 클릭하고 a와 동일한 url을 따르기를 원합니다. 이것은 HTML입니다 :IE7/8에서 window.location이 올바르게 작동하지 않습니다.
<div class="overview white getchildurl">
<p class="w70">
05-02-2011
</p>
<a class="button" href="details/">Details</a>
<span class="clear"></span>
</div>
나는이 스크립트가 :
$('.getchildurl').each(function() {
$(this).click(function() {
var href = $(this).children('a').first().attr('href');
window.location = href;
});
});
이 IE7과 IE8에서 파이어 폭스 3.6, 크롬, 사파리에서 작동하지만 없음. 페이지를 다시로드하지만 같은 페이지에 머물러 있습니다. 나는 var href를 검사했다, 그것은 적당한 url을 가지고있다. 그러나 거기에 가지 않는다. 내가 도대체 뭘 잘못하고있는 겁니까?
감사합니다.
편집 : 절대 URL로 설정하면 효과가 있습니다. 이 새로운 스크립트입니다
$('.getchildurl').each(function() {
$(this).click(function() {
var href = $(this).children('a').first().attr('href');
var host = window.location.hostname;
window.location = 'http://' + host + '/' + href;
});
});
'href' 속성을 명시 적으로 설정하십시오. 'window.location.href = href; ' – jAndy
window.location.href가 작동 할 수도 있습니다. ! –
저의 작품 : http://jsfiddle.net/ACaKu/ 거기 가서 확인해 주시겠습니까? 시도 할 몇 가지 사항 : "details /", location.href = href'에서 후행 슬래시를 제거하고 절대 경로를 사용하십시오. 'javascript : window.location = 'details /';를 입력하면됩니다. (0);'URL 바에서 –