NEW source file supporting multiple browsers!
Edit: Added some more explanation around the Content Editor and the script.
Embedding videos to the Body of a blog post in SharePoint has always required some tricks and coding.
If you Google the internet you may come accross posts like Embedding Flash Video in SharePoint Blogs by Kirk Evans and the ERTE project on Codeplex by Boris Gomiunik.
I've taken some inspiration in both these approaches, but wanted a solution that didn't include adding code to masterpages or installing solutions. Simplicity should be the key word. So my solution makes it possible to paste the embed code directly into the body text and hit Publish.And get the video working. To do this you simply add a Content Editor web part (CEWP) to the bottom of your page.
To edit the HTLM source of the CEWP (click Edit page and) click in the Editor part of the web part
Now in the ribbon locate the HTML icon, click the dropdown arrow and click on Edit HTML Source
Once in the HTML Source editor add the below script and click OK:
You can find the script file here: EmbedVideo.txt
Once the HTML Source editor is closed, click Page, Stop Editing.
After you done this the script should NOT show up on the page, if it does, then is has not been successfully entered into the HTML Source, examine it for any illegal characters that might occur from copying it from this page.
Once the script is successfully entered into the HTML of the CEWP you should be ready to move on!
Now you can paste the embed code directly into body text or you can even include embedded videos to items on a custom list or wherever you want...
And the result:
Or even in a custom list or as here a Link list using a Enhanced Rich Text field:
So, happy embedding :)
I am really interested in learning more about how this works. I have tried placing the code in several places and still can't seem to get it to work. I really need to be able to embed and use iframes in a custom list. i'm not trying on a blog but a custom list which has a rich text field for publishing. any suggestions?
ReplyDeleteHi Kristin. Did you add a Content Editor Web part to your page? And added the script to the HTML source by clicking HTML, Edit HTML Source? And finally, could you show me your embed code that you have added to the rich text field in your custom list?
DeleteI am displaying information from a list using the empty data view. i added the above code into the master page for the custom aspx page where the data view is. i then tried to use the embed code from a youtube video placing it directly into the body of a "Full HTML content with formatting and constraints for publishing" field.
DeleteOk, well, the script has been developed to fit the scenario of a rich text field and it is looking for a class of the name 'ExternalClass' before it looks for the iframe tag. All this is done (and the reason why I didn't go for at master page solution is) to optimize performance. Now if you know a little scripting you could remove some of the check or you could use IE developer tools (F12) to figure out which tags you have in your scenario. Or maybe go with some of the masterpage solutions I link to in the top of this post.
DeleteA colleague shared your solution with me recently - thanks so much! I was a big fan of Boris' ERTE code pre-SP2010, but LOVE the way this works too! Thanks! :)
DeleteThis comment has been removed by the author.
ReplyDeleteSorry was being slow and have copied your code into the HTML of a CEWP. The code shows when I look at the content of a blog post but no video appears. Embed code:
ReplyDeleteiframe width="560" height="315" src="http://www.youtube.com/embed/ZJbw3zYRaVA" frameborder="0" allowfullscreen></iframe
Hello, I am using the code below and it doesnt work. I have followed your instruction carefully.
ReplyDeletethe code im embedding is not allowed for submission on this page.
I'm sorry that it's not working for you, I editted my post with more details around the CEWP. Please let me know if this helps you.
ReplyDeleteSorry, I tried adding the CEWP with the code you provided in the html dialog but it does not work. I added your code to NewForm, EditForm and DisplayForm but still no video content displaying.
ReplyDeleteDear all
ReplyDeleteI just tried using the code from this web page and guess what? It failed! Turns out that you'll get illegal characters when you copy from here, so I removed the source window and added a link to the file directly.
Please retry with the correct script, thank you.
Hi Jesper,
ReplyDeleteExcellent work .It works fine for me. I just included your code in the master page (i'm using the CKS:EBE extension) of my blog site. Tested with IE8 and IE9.
I get an javascript error with Firefox and i don't see why. under investigation.
Gerald
The innerText is not supported by fx. a possible workaround is to use the contentText instead.
DeleteGerald
Thank you Gerald! I've updated the script to support multiple browsers using the technique from http://blog.coderlab.us/2006/04/18/the-textcontent-and-innertext-properties/
DeletePlease test is and let me know
Thank you, thank you, thank you! Tried numerous other scripts without luck and this one finally worked... and it was by far the simplest!
ReplyDeleteThis code worked wonderfully for me and I thank you very much for posting such an easy solution to a complex problem. My one problem is that any text in the entry that appears below the video does not appear in the post. Am I doing something that would make that occur or is this an issue with the code. Thank you for any answer you may have and thanks again for the code!
ReplyDeleteGood to hear that it worked. The code should leave any text below the video alone, so I'll need a little more information about how you do, which browser you use, the text you have inserted in the Body field and maybe a screenshot.
DeleteI am having a few issues with my email service, which means I cannot get those screenshots at this time. If this helps, I had simple text encased within paragraph HTML coding. The video was a .wmv file and we currently have IE8 deployed on our computers. I will try to straighten out the email issue I am experiencing and have some screen shots to give you at a later time. Thank you for responding!
DeleteHello again! I did resolve my issue, although I am not certain exactly what was occurring. I have a suspicion it involved an issue with our group's branding that caused the glitch. Thank you again for providing such a helpful resolution to our needs!
DeleteIt worked well the first time ! Amazing ! You are a genius !
ReplyDeleteThis actually worked and took me 2 minutes. Do you have any idea how many hours I have spent trying to get all of those ridiculously complicated ways people have posted to work (and they never do of course)? This is bloody brilliant. Tremendous hats off to you sir. This is just brilliant. Simple, effective and well communicated. Thank you!
ReplyDeleteThanks for the solution...worked for me..
ReplyDeleteAny possibility one can embed an iframe form in Sharepoint 2010?
ReplyDeleteHi Mark. I got no clue, never tried it before. I do see mr. Google raise some concerns about forms in iframes, but you could try it as the script does handle iframe tags.
DeleteThank you for the work. I have tried your solution and it did not work for me. I paste the code into the CEWP and then save it I get the following messge - Warning: The HTML source you entered might have been modified.
ReplyDeleteHow do you get around this
Hi 2824cops. Sorry to hear it didn't work. The warning you mention is 'normal' and shouldn't effect the script. You can check that it hasn't altered the script by re-opening the HTML Source code window as per description above, copy everything out to a new Notepad and compare it to the original script. The differences should be in formatting, linefeeds etc. A good tool for comparing text files is WinDiff. If there are differences you could try re-adding the original script. If the content of the HTML Source is identical to the original script I would like to get some details on how it didn't work. E.g. how does the embed code you are putting into the Blog post or Rich Text field look? And maybe some screenshots of how your page look after you added the script. You can find my email in my complete profile.
DeleteThanks for posting this for the world to use!
ReplyDeleteI've tried using this script and am not able to make it fully work.
I'm using this script on a Branded Web Part Page, so I've adjusted the class selector as appropriate (instead of externalclass).
When I load the page (with the iframe text in a CEWP and the script included as a Web Part), the iframe text disappears after an instant, but I do not see an embed appear on the page.
I've looked through the script, and I don't understand where in the code the embed actually gets put onto the page. Is it done simply through the unescape?
Actually, I have now tried the script with a video embedded from YouTube in an iframe, and that works just fine.
DeleteHowever, a website (such as https://www.google.com/) embedded in an iframe does not work.
Nevermind.... I think the problem lies in the way that my company has security and Sharepoint set up.
DeleteI can successfully embed a YouTube video and even this web page, but for some reason I can't embed Google or some other web pages.
Anyway, thanks for the script!
Thank you for this. I am able to embed videos from youtube. How can I embed videos from my local drive?
ReplyDeleteYou could just upload them to YouTube and then embed them this way
DeleteOr maybe upload them to a document library on SharePoint and embed them from there.
DeleteA colleague shared your solution with me recently - thanks so much! I was a big fan of Boris' ERTE code pre-SP2010, but LOVE the way this works too! Thanks! :)
ReplyDeleteAMAZING WORK! I had a little trouble making it work at first, I was trying to link to the text file instead of just copying the script in the CWP. But with a little help from my coworker we got it to work. Thank you!!
ReplyDeletePerfect, easy to implement solution - made my marketing team very happy. Cheers!
ReplyDeleteim trying this solution but is not working, and im getting this messages into console:
ReplyDeleteUncaught TypeError: Cannot read property 'className' of null
Uncaught TypeError: Cannot set property 'name' of null
Hello Salvador. Sorry to hear it not working for you. As you can see from the other comments it is working for most people, so it would be interesting to know you setup. Which browser and version are you using? Which version of SharePoint? And which type of document library? Any other info? If you know a little debugging try hitting F12 and examine the area around the embed code
Deletehi, i already fixed the errors but still not working, tried using an alert inside the if that execute the embedvideo function but it is not showing:
Deleteif (window['_spBodyOnLoadFunctionNames'])
{
_spBodyOnLoadFunctionNames.push("embedVideo");
}
else
{
embedVideo();
alert('embedvideoworks');
}
about your questions:
sharepoint 2010 standard
document library: posts
other info: Services Pack 1 With Cumulative Update June 2016
Try putting the alert into the start of the embedVideo function as it may be failing before it completes. Which browser are you using? IE x.xx? Also the column you are putting the embed code into has to be a rich text field like the Body of a blog post, otherwise the script may not find the needed fields
Deletetried the alert at start, it shows the alert.
Deleteabout rich text field, you are right the column is not rich text field, how can this be changed?
im using chrome and IE11
Go to Library settings, click on the column, choose multiline + rich text, not plain text and not enchanced
Deleteverified and it is already rich tex field
Deletehey, i did this and worked:
Delete<_script type="text/javascript">
$('div[class*=ExternalClass]').each(function(){
var $this = $(this);
var t = $this.text();
$this.html(t.replace('<','<').replace('>', '>'));
});
but is only working in desktops, tried on android and is not working
i have an update, it is working on android, it was a ssl problem :D
DeletePerfect! Nice to know and thanks for reporting your solution back.
DeleteThis comment has been removed by the author.
ReplyDeleteI'm having trouble getting this to work right. I added the CEWP and put in the code. Now, when I create a blog post with the embedded iframe code from YouTube, all I get is a black rectangle (no video). I'm using SharePoint 2010 Enterprise, a SharePoint blog site, the Body field is rich text, and I'm trying to view it using Internet Explorer 11. Any ideas?
ReplyDeleteSorry to hear that, no I don't really have any ideas, maybe try looking at Compatibility settings or try using e.g Chrome, just to see if that works
DeleteYOU ARE MY HERO!!!!!!!!! REALLY, the ONLY solution that worked for me in Sharepoint 2010. I was about to throw myself out of the window after spending hours with the other solutions. Amazing!!! Thank you!
ReplyDeleteInformative article, just what I was looking for. insert video html
ReplyDelete