I have the following code that loads a tile, or "widget", in my UI. Occasionally (like on orientation change) I have to redraw the tiles. Some of the content is generated by a script load event. During the redraw, this event is not getting loaded again. How can I accomplish this?
//html
let $elTile = $('<div/>').appendTo($elContainer);
$elTile.load('tiles/' + tile.name + '/' + tile.name + '.html #' + tile.name + '-content');
//javascript
$.getScript('tiles/' + tile.name + '/' + tile.name + '.js');
//css
$('head').append( $('<link rel="stylesheet" type="text/css" />')
.attr('href', 'tiles/' + tile.name + '/' + tile.name + '.css'));
And here is what one of the tile script files looks like:
window.addEventListener("load", function() {
//do some stuff that may need to be called again on orientation change
});
I see from questions like this and this that I probably can't just "unload and reload" the script, so is there another way to process the "tile initialization" script again?
Orientation Change was just an example, I'd like to be able to call the tile init script arbitrarily if possible.