samedi 25 juin 2016

continuously check URL until string is present, run javascript code when found

i need some help with this code. i want to read the current URL, and when the URL contains "#_ThankYou" in it, I want to add a new to an existing on the page and that div contains some javascript that will display an ad from an ad vendor. i have the following but i think i might be caught in an infinite loop. not sure i coded this correctly. anyone have good suggestions? <script type="text/javascript"> window.eddyCookieCount = 0; window.eddyNumberAttempts = 0; window.myInterval = setInterval(function() { if (window.location.href.indexOf("#_ThankYou") > window.eddyCookieCount) { jQuery('div.thankyou-container').append('<div>' + vm_load({ "displayId": "12584", // Numeric unique ad display Id "publisherId": "33927", // Publisher ID "campaign": "9380", // Numeric Publisher Campaign Id "maxResults": "3", "areaofstudy": JSON.parse(jQuery.cookie('CategorySubCategorySpecialty')).CATEGORIES[0].text.replace('Business','1').replace('Criminal Justice & Legal','3').replace('Education','5').replace('Fine Arts & Design','2').replace('Health & Medicine','8').replace('Liberal Arts & Humanities','5').replace('Math, Science & Engineering','9').replace('Public Affairs & Social Sciences','13').replace('Religious Studies','5').replace('Technology','9').replace('Vocational Training',''), "md": "1" }) + '</div>'); window.eddyNumberAttempts++; if (window.eddyNumberAttempts > 60) { window.eddyCookieCount = jQuery.cookie('CategorySubCategorySpecialty').length; window.eddyNumberAttempts = 0; } } else if (jQuery.cookie('CategorySubCategorySpecialty').length < window.eddyCookieCount) { window.eddyCookieCount = jQuery.cookie('CategorySubCategorySpecialty').length; } }, 50); </script>

Aucun commentaire:

Enregistrer un commentaire