2012-05-04 2 views
0

google plus 코드를이 방법으로 사용하는 것이 IE8이나 다른 버전에서 작동하지 않는 이유는 무엇입니까? 그래도 파이어 폭스에서 잘 작동합니다.IE8의 자바 스크립트 괴짜, document.write 문제

라이브 데모 : http://jsfiddle.net/9zqsZ/

<script> 

var socialString = '<g:plusone size="tall"></g:plusone>'; 
document.write(socialString); 

    //google plus share button 
    (function() { 
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; 
    po.src = 'https://apis.google.com/js/plusone.js'; 
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); 
    })(); 

</script> 

난 그냥 외부 파일에 넣어 노력하고 있어요. 이상한 것은 document.write에서 작동하지 않고 html에 직접 배치되는 경우에만 작동한다는 것입니다. 이 경우 어떻게 구현합니까?

답변

1

당신은 무언가 같이 할 수있는 :

<script> 
    if (navigator.appVersion.indexOf("MSIE") != -1) { 
     var socialString = '<g:plusone size="tall"></g:plusone>'; 
     var newEle = document.createElement(socialString); 
     document.body.appendChild(newEle); 
    } 
    else { 
     var socialString = '<g:plusone size="tall"></g:plusone>'; 
     document.write(socialString); 
    } 

    //google plus share button 
    (function() { 
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; 
    po.src = 'https://apis.google.com/js/plusone.js'; 
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); 
    })(); 
</script> 
+0

내 콘솔 코드 – devjs11

+0

그게 이상한 "문자열에 잘못된 문자가 포함을"퍼팅 오류를 반환, 그것은 IE8에서 나를 위해 일한 될 수있는 몇 가지 추가 문자가 추가되었다 동안 당신은 코드를 복사 한 후 pls가 한 번 –

+0

ok가 잘 작동하는지 확인합니다. 편집 된 대답을 확인하십시오. –