Francis Alvin Tan
Francis Alvin Tan

Reputation: 1087

replace a string in a youtube embed code using jquery

I have here an embed code from youtube and Im using a plugin to show that video

<object width="350" height="200">
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://www.youtube.com/v/KVu3gS7iJu4&autoplay=0&loop=0&rel=0" />
<param name="wmode" value="transparent">
<embed src="http://www.youtube.com/v/KVu3gS7iJu4&autoplay=0&loop=0&rel=0" type="application/x-shockwave-flash" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" width="350" height="200">
</embed>
</object>

My problem is I cannot edit those codes, I need to change the "&" sign to "&amp;" for w3c validation, is this possible using jquery

here is My sample fiddle which is not working and dont know how http://jsfiddle.net/kfX9M/

Upvotes: 1

Views: 343

Answers (2)

John Peter
John Peter

Reputation: 2928

Hi dude i did with jQuery and Regular Expressions.,

<script type="text/javascript">
$(document).ready( function() {

var re=/&/g;

var value=$("param[name='movie']").val();

var modified_value=value.replace(re,'&amp;');

$("param[name='movie']").val(modified_value);

var src = $("embed").attr('src');

var src_modified_value=src.replace(re,'&amp;');

$("embed").attr('src',src_modified_value);

});
</script>

i think this may help you to resolve your problem.

To see it in action : http://jsfiddle.net/john_rock/7H2Hk/

Upvotes: 0

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324650

Changing it with jQuery won't make your HTML valid. You could change it server-side with some PHP:

$dom = new DOMDocument();
$dom->loadHTML($your_embed_code_here);
$xpath = new DOMXPath($dom);
$items = $xpath->query("//*[contains(@href,'&')]");
$l = $item->length;
for($i=0; $i<$l; $i++) {
  $items->item($i)->setAttribute("href",str_replace("&","&amp;",$items->item($i)->getAttribute("href")));
}
$out = $dom->saveHTML();

But, as mentioned by elclanrs, it really makes no difference.

Upvotes: 2

Related Questions