Skip to content Skip to sidebar Skip to footer

How To Add Multiple Events For “input” In Post Messages

I have simple input and HTML5 video player with iframe, I want to add multiple events to input with post message. Problem. I want on input focus event it should play video1 if use

Solution 1:

I was able toget your Plunker to work: https://next.plnkr.co/edit/Pm4vWqp4n4kKIq5H?preview=formpage.html

Make sure to Preview the formpage.html as the index.html is not where this issue lays. Here are the changes I would suggest for your form.js file:

$(function() {
    $(window).resize(resizeIframe);
    $(window).resize();
    $('#name').on('focus', function() {
        $('#videoframe')[0].contentWindow.postMessage(
            'event=fieldchanged&fieldtype=name&value=' + $('#name').val(),
            '*'
        );
    });
    $('#name').on('keyup', function() {
        $('#videoframe')[0].contentWindow.postMessage(
            'event=fieldchanged&fieldtype=name&value=' + $('input#name').val(),
            '*'
        );
    });
});

functionresizeIframe() {
    console.log(($('iframe#videoframe').width() * 576) / 1024);
    $('iframe#videoframe').height(
        ($('iframe#videoframe').width() * 576) / 1024
    );
}

This appears to do what you wanted, when it got focus, it started playing. When I pressed a key, it started playing again at the new header.

If it were me, I would consider JSON format. This way you can create objects or arrays of the events and actions and then stringify them for the post message.

When I review videoframe.js, I cannot determine where $(input) is defined. This ends up throwing an error in console on keyup.

If this is not working as expected, then please clarify what should be happening. Be precise. Walk us through all the steps.

Post a Comment for "How To Add Multiple Events For “input” In Post Messages"