Question

How can I change the ID of the embedded vimeo video? Here is the embed code for example:

<object width="578" height="325">
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=11527784&amp;
server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" />
<embed src="http://vimeo.com/moogaloop.swf?clip_id=11527784&amp;
server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;
color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" 
allowscriptaccess="always" width="578" height="325"></embed></object>

How can I change the clip_id in both the object value and the embed source using JQuery or just pure javascript?

The effect this has is that it changes the video. I have tested this on Firefox, if this won't work on all browsers please let me know!

Thanks all for any help

Was it helpful?

Solution

I am not sure "when" you want to replace it, so I made it on click. Try this:

$('#change_me').click(function() {
    var val = $('embed').attr('src').replace(/clip_id=(?=\d).\d+/g, 'clip_id='+new_id);


    $('embed').attr('src', val);
    alert($('embed').attr('src'));
});

This regular expression will find clip_id followed by any numbers and only numbers and replace them with the new id. You can do this on both urls that contain clip_id. I am pretty sure it will work on all browsers, although I cant test it right now.

Note: I am sure that a better regular expression could be used, but I am not particulary good with them, so thats all I can come up with atm.

Hope this helps

OTHER TIPS

There are some cross-browser implications for this.

You might want to take a look at another question on SO.

You should use the SWFObject plugin for this as stated by SolutionYogi.

Here's another related question: How to use javascript to swap swf in html?

    var params = document.getElementsByTagName("param");
    var clip_url = 11527780;
    var vimeo = "http://vimeo.com/moogaloop.swf?clip_id=" + clip_url + "&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1";
    params[2].setAttribute("value", vimeo);

    var embed = document.getElementsByTagName("embed");
    embed[0].setAttribute("src", vimeo);

clip_url is the id of the vimeo video.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top