In my previous post I learned you how to integrate YouTube in SharePoint 2010 Blogs. Now I will teach you how you can use that script, though a bit tweaked, for YouTube and Google Maps integration anywhere on your site (ie. in Publishing Pages).
Go to SharePoint Designer 2010 and open your masterpage. Scroll completely to the bottom and add following pieces of Javascript below the -/body- tag.
try{
//replace [youtube]url[/youtube] tags with corresponding HTML object
if (document.getElementById("page_content").innerHTML.indexOf("[youtube]") > -1) {
//find all [youtube][/youtube] tags
var arr = document.getElementById("page_content").innerHTML.split("[youtube]");
var tempSrc = document.getElementById("page_content").innerHTML;
for (j = 0; j < arr.length; j++) {
//get the url between the [youtube][/youtube] tags
urltemp = arr[j].substring(0, arr[j].indexOf("[/youtube]"));
if (urltemp == "") continue;
//format the URL to the correct format to use with the object-element
url = urltemp.replace(/<.*?>/g, '').replace("/watch?v=", "/embed/");
//replace the [youtube][/youtube] tags with the corresponding object-element
tempSrc = tempSrc.replace("[youtube]" + urltemp + "[/youtube]", "<iframe width='480' height='390' src='"+ url +"' frameborder='0' allowfullscreen></iframe>");
}
document.getElementById("page_content").innerHTML = tempSrc;
}
//replace [googlemaps]url[/googlemaps] tags with corresponding HTML object
if (document.getElementById("page_content").innerHTML.indexOf("[googlemaps]") > -1) {
//find all [googlemaps][/googlemaps] tags
var arr = document.getElementById("page_content").innerHTML.split("[googlemaps]");
var tempSrc = document.getElementById("page_content").innerHTML;
for (j = 0; j < arr.length; j++) {
//get the url between the [googlemaps][/googlemaps] tags
urltemp = arr[j].substring(0, arr[j].indexOf("[/googlemaps]"));
if (urltemp == "") continue;
url = urltemp.replace(/<.*?>/g, '');
//replace the [googlemaps][/googlemaps] tags with the corresponding object-element
tempSrc = tempSrc.replace("[googlemaps]" + urltemp + "[/googlemaps]", "<iframe width='480' height='375' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='" + url + "&output=embed'></iframe><br /><small><a href='" + url + "' style='color:#0000FF;text-align:left' target='_blank'>Grotere kaart weergeven</a></small>");
}
document.getElementById("page_content").innerHTML = tempSrc;
}
}
catch(err){}
What I basically do is look up the tags in a div called "page_content", which contains all of the page content, and replace the corresponding tags.
For YouTube you just copy paste the url between [youtube]http://www.youtube.com/watch?v=j3U7TAqbSds[/youtube] tags.

For Google Maps you use the url you find under the link. [googlemaps]http://maps.google.be/maps?q=gent&hl=nl&sll=50.503887,4.469936&sspn=4.772562,13.392334&t=h&z=12[/googlemaps]

I hope you can use this little piece of code in your SharePoint 2010 Blogs as well. I cannot guarantee this will work without any tweaking of the script. But it might push you in the right direction.
Enjoy!




