LinkedIn の共有ボタンは、次のコードを使用してページに追加できます。
<script src="//platform.linkedin.com/in.js" type="text/javascript"></script>
<script type="IN/Share" data-counter="top"></script>
ボタンの上にあるようにデータカウンターを動的に変更できるようにしたいと思います。
これを行うために、古いものを削除LinkedIn button
し、次のコードで新しいものを追加しました。
addScript = function(counterPosition) {
mainElement = document.getElementById("scripts-go-here");
d = document.createElement("script");
d.type="IN/Share";
d.setAttribute("type", "IN/Share");
d.setAttribute("data-counter", counterPosition);
// Reset the current element, since we only want to change the layout of the button
while(mainElement.firstChild) {
mainElement.removeChild(mainElement.firstChild);
}
mainElement.appendChild(d);
IN.parse();
}
addScript("right");
addScript("top");
ただし、この jsfiddle でわかるように、問題は、直後にいくつかの JS エラーが表示されることです。
「キャッチされていない TypeError: null のプロパティ 'innerHTML' を設定できません」
なぜこれが起こるのですか?どうすればこれを回避できますか?
これは Linkedin の jsApi の問題ですか?