jQuery .load() call doesn't execute JavaScript in loaded HTML file

后端 未结 13 1725
难免孤独
难免孤独 2020-11-22 08:28

This seems to be a problem related to Safari only. I\'ve tried 4 on Mac and 3 on Windows and am still having no luck.

I\'m trying to load an external HTML file and

13条回答
  •  情话喂你
    2020-11-22 08:55

    Tacking onto @efreed answer...

    I was using .load('mypage.html #theSelectorIwanted') to call content from a page by selector, but that means it does not execute the inline scripts inside.

    Instead, I was able to change my markup so that '#theSelectorIwanted'became it's own file and I used

    load('theSelectorIwanted.html`, function() {}); 
    

    and it ran the inline scripts just fine.

    Not everyone has that option but this was a quick workaround to get where I wanted!

提交回复
热议问题