javascript - Image in formatSelection markup is broken when sending user to new page on selecting event -


if have markup formatselection includes image , have window.location.href in select2-selecting event, image broken. if remove window.location.href, image works , can seen before new page loaded.

$('.select2#topbarsearch').on("select2-selecting", function(e) {      window.location.href = 'www.example.com'; });   function selectionformat(data) {          var markup = "<table class='search-result'><tr>";         if (data.image !== undefined) {             markup += "<td class='data-image'><img style='height: 25px;' src='" + data.image + "'/></td>";         }         markup += "<td class='data-info-selected'><div class='data-title'>" + data.title + "</div>";         markup += "</td></tr></table>";         return markup; } 

the image has verified it's done loaded before redirecting user.

var img = new image(); img.src = e.object.image; img.onload = function(){     window.location.href = scriptpath + 'item/' + e.object.id; }; 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -