0

I'm using Ajax to load a page, and on that page I'm loading an external script from issuu.com. It works very nicely the first time either I or Ajax load the page, but if Ajax loads a new page and then goes back again it will not run the external script again (It loads the script, but doesn't execute it).

This is the page: http://dymak-corporate.134.lait.dk/catalogue/

You can see in e.g. the network tab of your browser's dev tools that it loads the script both times, but only executes the first time.

I have tried to load and execute the script in every way I can think of and nothing is working.

jQuery GetScript:

 $.getScript("//e.issuu.com/embed.js")

Ajax load the script and eval it:

$.ajax({
    url: "/scripts/embed.js",
    success: function (responseText) {
        eval(responseText);
    }
});

Adding it to the header every time and removing it before I add it:

$('#issuuScript').remove();
var s = document.createElement("script");
s.id = "issuuScript";
s.src = "//e.issuu.com/embed.js";
document.head.append(s);

Reloading it at every load:

function reload_js(src) {
    $('script[src="' + src + '"]').remove();
    $('<script>').attr('src', src).appendTo('head');
}
reload_js('/scripts/embed.js');

I also tried adding it inline, without success.

Zero Piraeus
  • 56,143
  • 27
  • 150
  • 160
Kim
  • 51
  • 4
  • Issuu has actually updated their embed scripts to also support dynamically created embeds. You should be able to succeed with your original approach. – WrongAboutMostThings Jul 23 '13 at 11:38

2 Answers2

0

This is not how JavaScript is supposed to work. A file include is not a like a function call, but you are treating it like a function call.

How you should think about it:

I want to call some_module.some_function(). Is some_module loaded?

No. Load the file that has the module, then execute the function.

Yes. Just execute the function.

Halcyon
  • 57,230
  • 10
  • 89
  • 128
  • I would like to execute it like a function if i could, but it is a self invoking anonymous function – Kim Jun 25 '13 at 15:08
0

I ended up just using the iframe implementation from issuu

Kim
  • 51
  • 4