Advertisement
Guest User

Click Hander for Direct MOV Links to Embed QuickTime Plugin

a guest
Mar 26th, 2016
1,597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2. function embedMOV(evt){
  3.     // Check for video/quicktime plugin support
  4.     if (!navigator.mimeTypes['video/quicktime']) return;
  5.     // Derive target element
  6.     var movLink = evt.target;
  7.     // Build object
  8.     var obj = document.createElement('object');
  9.     obj.setAttribute('type', "video/quicktime");
  10.     obj.setAttribute('data', movLink.href);
  11.     obj.setAttribute('autoplay', 'true');
  12.     obj.setAttribute('style', 'width:95%; height:95%; margin-left:auto; margin-right:auto;');
  13.     // Write to the target frame
  14.     var w = window.frames[movLink.target];
  15.     var b = w.document.body;
  16.     b.innerHTML = '<p><a href="' + movLink.href + '">' + movLink.href + '</a></p>';
  17.     b.insertBefore(obj, b.firstChild);
  18.     // Cancel link navigation
  19.     evt.preventDefault();
  20.     evt.stopPropagation();
  21.     return false;
  22. }
  23. function prepLinks(){
  24.     // Find links to .mov files
  25.     var movs = document.querySelectorAll('a[href*=".mov"], area[href*=".mov"]');
  26.     // Add click handler to embed the plugin
  27.     for (var i=0; i<movs.length; i++){
  28.         movs[i].addEventListener('click', embedMOV, false);
  29.     }
  30. }
  31. if (navigator.userAgent.indexOf('Firefox') > -1){
  32.     window.addEventListener('load', prepLinks, false);
  33. }
  34. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement