/ Published in: JavaScript
zanox Web Services - Contextual Product Search Widget for blogger.com
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<ul id="zxAdList"></ul> <script type="text/javascript"> function addScript(url) { var script = document.createElement('script'); script.src = url + '&t=' + new Date().getMinutes(); script.type = 'text/javascript'; document.getElementsByTagName('head')[0].appendChild(script); } function productSearch(version, applicationid, adspace, region, programs, minPrice, maxPrice, category, page, items, q, callback) { var url = 'http://api.zanox.com/json'; if (version) url+= '/' + version; url += '/products?applicationid=' + applicationid; if (adspace) url += '&adspace=' + adspace; if (region) url += '®ion=' + region; if (programs) url += '&programs=' + programs; if (category) url += '&category=' + category; if (page) url += '&page=' + page; if (items) url += '&items=' + items; if (minPrice) url += '&minPrice=' + minPrice; if (maxPrice) url += '&maxPrice=' + maxPrice; if (callback) url += '&callback=' + callback; if (q) url += '&q=' + q; addScript(url); } function renderLinkListItem(content, link, itemContainer) { var li = document.createElement("li"); li.innerHTML = '<a href="' + link + '">' + content + '</a>'; itemContainer.appendChild(li); } function handler(data) { if (data.productsResult) { var productItems = data.productsResult.productItem; var zxAdList = document.getElementById('zxAdList'); //ID of a UL HTML element for (var i = 0; i < productItems.length; i++) { var productItem = productItems[i]; var link = ''; if (productItem.url.adspace instanceof Array) { // select tracking link related to the first Adspace link = productItem.url.adspace[0].$; } else { link = productItem.url.adspace.$; } var content = productItem.name + ' bei ' + productItem.program.$ + ' für ' + productItem.price + ' ' + productItem.currency; renderLinkListItem(content, link, zxAdList); } } } var zx_query = document.getElementsByTagName('h3').item(0).getElementsByTagName('a').item(0).innerHTML; //contextual product search parameters: version, applicationid, adspace, region, programs, minPrice, maxPrice, category, page, items, q, callback productSearch(null, 'BE94C4947839E8AB4D67', null, 'de', '660', null, null, null, 0, 5, zx_query, 'handler'); </script>