Support » Plugin: WP YouTube Lyte » [Plugin: WP YouTube Lyte] Uncaught TypeError: … has no method 'getElementByID'

  • Resolved Eric McNiece


    Hello again!

    My plugin suddenly stopped working. It’s returning an error:
    Uncaught TypeError: Object Mon Nov 21 2011 10:44:03 GMT-0800 (Pacific Standard Time) has no method ‘getElementById’

    from line 324, which is this:
    var bU='';var d=document;if(d.addEventListener){d.addEventListener('DOMContentLoaded', insert, false)}else{window.onload=insert} function insert(){if(!d.getElementById('lytescr')){lytescr=d.createElement('script');lytescr.async=true;'lytescr';lytescr.src='';h=d.getElementsByTagName('script')[0];h.parentNode.insertBefore(lytescr, h)}};

    The function I use to call the player is this:

    <?php 	if(get_field('music_videos')){
    					if(function_exists('lyte_parse')) while(the_repeater_field('music_videos')) echo lyte_parse(str_replace('http://', 'httpv://', get_sub_field('youtube_url')));

    Any ideas as to where to start looking? As always, thanks for your awesome support 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Frank Goossens


    a wild guess; you (or some of the javascript code you wrote/ an other plugin generates) store the date in d, while the lyte javascript wants to use it as shorthand for “document”? in which case d.getElementById indeed would not work as the string has no method by that name?

    Haha, awesome guess… earlier on the page there’s a jQuery date picker with new Date(d.getFullYear(), 1-1, 1).

    Is it safe to change the variable for Youtube Lyte? Or maybe should I insert a chunk of code to clear d?

    Plugin Author Frank Goossens


    you can change the variable for youtube lyte, but you’ll have to re-apply that change when upgrading off course. so some code to clear the “d=new Date();” from the jQuery datepicker could be more futureproof.

    but i’m not sure what the best solutin would be, best to try and see what happens i guess.

    Alright… sorry to keep bugging you, but I’m stumped again. I’m playing with the code:

    <script type="text/javascript">delete d; var d=document; alert(d);</script>

    The date d var is being created in the head; the document d var is being used in the body. I’ve tried placing this code all over the place, but it’s still throwing that error. I need another hint 🙂

    Should I be placing this in a script and using wp_enqueue_script?

    It’s the MailChimp plugin Version 1.2.6 | By MailChimp and Crowd Favorite. They have a little jQuery routine for a datepicker. I’m not using that particular feature so I changed their variable from ‘d’ to ‘e’, but yes, that will only last so long.

    mailchimp.php lines 145, 151, 152.

    I’ll have to do some more investigating as to how this can be avoided in the future. It stands to reason that with thousands of plugins some people would use the same variable names… I wonder how they prevent situations like this?

    Thanks for the push.

    Plugin Author Frank Goossens


    I’ve always struggled with javascript-scope as well, i always take the trial & error approach 😉

    Does mailchimp use a datapicker in the frontend (for visitors)? I would expect it to be only used in the backend, so the datepicker jquery plugin shouldn’t even be loaded in the frontend html?

    I’ll look into javascript scope & closure to see how I could ‘protect’ wp-youtube-lyte’s javascript from “collisions” like this. hopefully I can solve this for a future release.

    Yeah, the datepicker is for the front-end. Turns out there’s an option to disable it in the admin, but even so… what if somebody needed it?

    In the quest for education I posted this:

    Very informative! I’m going to start using this for my own projects as well. Fortunately, wp-youtube-lyte is small enough that doing this shouldn’t take too long 🙂

    Plugin Author Frank Goossens


    indeed, a closure. ain’t stackoverflow great? 🙂

    i assumed (re-)declaring “var d=document;” would be sufficient to ensure i’ve got the right object, but apparently not.

    i’ll add this on my todo list for 0.9.3 (or, who knows, magical 1.0.0). but as you’ve got the problem solved, I won’t hurry this new version out. don’t want to push a 4th version in only a couple of weeks time. people tend to not like updates that are too frequent.

    Plugin Author Frank Goossens


    update: i’ve pushed corrected code to trunk on the wordpress plugin svn.

    changed files:

    • wp-youtube-lyte.php
    • widget.php
    • readme.txt
    • lyte/lyte.js
    • lyte/lyte-min.js

    tested on a couple of browsers and all seems to work ok, should be a better solution to your problem. this will be included in the next version of WP YouTube Lyte.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Plugin: WP YouTube Lyte] Uncaught TypeError: … has no method 'getElementByID'’ is closed to new replies.