2011-07-29 54 views
4

我正在網站上工作,我需要在將按鈕放在頁面上之前構建一個URL。下面是它如何工作的:在IE 8的頁面加載後添加Google +1按鈕

var googleplus = $("<g:plusone size='tall' href='http://google.com'></g:plusone>"); 
$("#container").append(googleplus); 
gapi.plusone.go(); 

而在頭我有這樣的:

<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> 

這在Firefox/Chrome瀏覽器/ IE 9,但不是IE 8.我在茫然,還有什麼可以做到的。我嘗試了gapi.plusone.render()方法,但仍然沒有運氣。

回答

4

這裏是解決方案,它爲我工作在兩個IE7/8:

var gPlusOne = document.createElement('g:plusone'); 
gPlusOne.setAttribute("size", "tall"); 
gPlusOne.setAttribute("href", "http://google.com"); 
container.appendChild(gPlusOne); 
看來,使用innerHTML來一個 <g:plusone></g:plusone>元素插入到頁面中並沒有在IE7/8的工作,創建

對於g :plusone直接像這樣:document.createElement('g:plusone'). 查看更多:http://www.google.com/support/forum/p/Webmasters/thread?tid=3d63228b915dab32

+0

雖然這幫助了特定版本的IE8(v 8.0.7600.16385),但它並沒有幫助IE7。至少我更接近聖盃。 FWIW,看起來IE7存在問題,Google表示他們不支持IE7(請參閱http://www.google.com/support/accounts/bin/answer.py?hl=zh_CN&answer=1151309) – DMCS