The booking.com
hotel listings widget is not launching with the “iframes” as required, in case of my dynamic table listing.
Hence I tried to create an .init(Booking) function by nesting the javascript of the widget within another function that I named Booking as below.
(function(Booking) {
(function(d, sc, u) {
var s = d.createElement(sc), p = d.getElementsByTagName(sc)[0];
s.type = 'text/javascript';
s.async = true;
s.src = u + '?v=' + (+new Date());
p.parentNode.insertBefore(s,p);
})(document, 'script', '//cf.bstatic.com/static/affiliate_base/js/flexiproduct.js');
});
And then I applied the .Init(Booking) to the jquery script which creates the html with the respective booking codes as below.
jQuery('#divResult table tbody tr td').each(function ($) {
if (jQuery(this).text() == 'Hotel') jQuery(this).nextAll("td").each(function ($) {
var DataAid = jQuery(this).text().split('/')[0];
var DestAid = jQuery(this).text().split('/')[1];
var DestType = jQuery(this).text().split('/')[2];
jQuery(this).html('<div style="width:100%; margin-top:4px;"><ins class="bookingaff" data-aid="'+ DataAid +'" data-target_aid="'+ DataAid +'" data-prod="dfl2" data-width="100%" data-height="auto" data-lang="en" data-dest_id="'+ DestAid +'" data-dest_type="'+ DestType +'" data-df_num_properties="3"><a href="//www.booking.com?aid='+ DataAid +'">Booking.com</a></ins></div>')
}).init(Booking)
});
});
However, this is not working and the ‘iframes’ in the widget still do not load. I get the error " Uncaught Reference Error: Booking is not defined ". How do I solve this?
JS Fiddle: https://jsfiddle.net/3r4210Lb/1/