上記のMTタグは、以下のHTMLとJavaScriptを出力します。
この記事は
<script type="text/javascript">
function scoredby_script_vote(id) {
var xh = getXmlHttp();
if (!xh) return false;
xh.open('POST', 'http://example.com/cgi-bin/mt-cp.cgi', true);
xh.onreadystatechange = function() {
if ( xh.readyState == 4 ) {
if (xh.status && ( xh.status != 200 ) ) {
// error - ignore
} else {
eval( xh.responseText );
}
}
};
xh.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
xh.send( '__mode=vote&id=' + id + '&blog_id=9&f=scored,sum&jsonp=scoredby_script_callback' );
}
function scoredby_script_callback(scores_hash) {
var true_block = getByID('scored_' + 2062);
var false_block = getByID('scored_' + 2062 + '_else');
var span;
if (scores_hash['2062'] && scores_hash['2062'].scored) {
span = getByID('cp_total_' + 2062);
if (true_block)
true_block.style.display = '';
if (false_block)
false_block.style.display = 'none';
}
else {
span = getByID('cp_total_' + 2062 + '_else');
if (true_block)
true_block.style.display = 'none';
if (false_block)
false_block.style.display = '';
}
if (span) {
if (scores_hash['2062'] && scores_hash['2062'].sum)
span.innerHTML = scores_hash['2062'].sum;
else
span.innerHTML = 0;
}
}
</script>
<div id="scored_2062" class="scored" style="display:none">
お気に入り登録されています。
</div>
<div id="scored_2062_else" class="scored-else" style="display:none">
お気に入り登録されていません。
</div>
<script type="text/javascript" src="http://example.com/cgi-bin/mt-cp.cgi?__mode=score&blog_id=9&id=2062&f=scored,sum&jsonp=scoredby_script_callback"></script>
mt:IfEntryRecommended タグを正しく動作させるためには、以下のJavaScriptコードを、出力されるページに記述する必要があります。
function getByID(n, d) {
if (!d) d = document;
if (d.getElementById)
return d.getElementById(n);
else if (d.all)
return d.all[n];
}