I have some code that checks to see what event data is being passed back from two different media players. The first player sends back play button clicked, but the second player sends back the data I want but it's I have to parse it and read it to see if it matches play and startPosition === 0.

Wondering if there is a better way to check both the players to see what data is being passed in. What I have just feels dirty.

function handleWindowMessage (e) {
    var originalEventData = e.originalEvent.data;

    if (originalEventData === 'play button clicked') { 
        _gaq.push('_trackEvent', 'Video', 'Played');

    try {
        var parsedData = JSON.parse(originalEventData).data;

        if (parsedData && parsedData[0] === 'play' && parsedData[1].startPosition === 0) {
            _gaq.push('_trackEvent', 'Video', 'Played');
    catch (ignore) {}
    finally { return; }

$(window).on('message', handleWindowMessage);
  • \$\begingroup\$ This isn't really large enough for an entire review, but, you may not need to use === everywhere, most evaluations support ==. \$\endgroup\$ – Quill Jul 28 '15 at 23:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.