2011-02-11 4 views
0

Joomla 사이트 및 jQuery와의 호환성 문제가 발생하지만 새 창에서 외부 링크를 여는 데 아주 잘 작동하는 jQuery 코드가 있습니다. 나는 과거에이 문제에 부딪쳤다. 그리고 그것을 해결하는 가장 쉬운 방법은 Joomla 시스템 Mootools 라이브러리를 사용하는 것이다.jQuery를 Mootools로 변환

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>   
<script type="text/javascript">           
    $(document).ready(function() { 
     $('a[href^="http://"]').filter(function() {return this.hostname && this.hostname !== location.hostname;}).attr('target', '_blank'); 
    });      
</script> 

누군가가 나에게 위의 코드를 변환 도와주세요 수 :

여기 JQuery와 내가 Mootools의로 변환 할 필요 스크립트입니까?

Mootools는 이미 시스템 플러그인을 통해 활성화되어 있습니다.

+1

더 나은 네임 스페이스를 사용할 수 있습니다. – Yahel

+0

[jquery api] (http://api.jquery.com/)에서'noconflict'를 체크 아웃하십시오. jQuery에서'document.ready' 이벤트를 선언하는 가장 좋은 방법은 다음과 같습니다 :'jQuery (function ($) {... your code here ...}); 함수의 문맥. – zzzzBov

+0

그래서이 코드는 href 속성에 페이지가 현재 제공되고있는 호스트 이름과 다른 호스트 이름을 포함하는 모든 앵커 태그에 target = "_ blank"를 추가합니까? 또는 tl; dr : 외부 사이트를 새 창에서 엽니 다. 권리? –

답변

3

다시 당신이 jQuery를 그것을했다

Slick.definePseudo('external', function() { 
    return this.hostname && this.hostname != window.location.hostname; 
}); 

document.getElements('a[href^=http://]:external').set('target', '_blank'); 

또는 그대로 새로운 의사 선택을 설정할 수 있습니다 외부 링크를 선택 할 수 있습니다합니다.

document.getElements('a[href^=http://]').filter(function(a) { 
    return a.hostname && a.hostname != window.location.hostname 
}).set('target', '_blank'); 
+0

첫 번째 옵션은 Mootools 1.3에서만 작동하지만 두 번째 옵션은 1.2와 1.3에서 모두 작동합니다 – Jacob

0
$('a').each(function(el){ 
    /* check el.href and if test is true => */ 
    el.set('target','_blank')} 
); 
+0

감사합니다. Box9 저는 제 아이폰 xD에 있습니다. – stecb

0

저는 mootools에 익숙하지 않지만 이와 비슷한 것을 시도해 보셨습니까?

Snipplr.com는 : automatically send external links to new window with mootools

... 정말 당신도 Mootools의 필요하지 않습니다, 당신은 당신이 충돌이 염려되는 경우 자바 스크립트 바닐라에 그것을 할 수 있습니다.

관련 문제