javascript - load script using jquery ajax and remove based on change of a variable -
i adding google api script using jquery ajax, based on language lang
chosen user inside app:
var src = ''; if (lang == 'en') { src = 'https://script1.googleapis.com/script1'; } else { src = 'https://script2.googleapis.com/script2'; } jquery.ajax({ url: src, datatype: 'script', success: function () { }, async: true });
once added, when user changes language, second script gets added page, , error:
you have included google maps api multiple times on page. may cause unexpected errors.
how can remove old script once language changed? each time script corresponding chosen language of site loaded?
thanks
once script loaded, objects , functions defines kept in memory. best can is remove globally delete window.ga
, load again script.
and if duplication of script on dom remove before calling next script.
Comments
Post a Comment