Video Overlay Hidden Behind YouTube Playback

I'm currently facing an issue with my website that includes a YouTube video. Whenever I try to open a popup window using JavaScript, it appears behind the YouTube video instead of on top. I have attempted to adjust the z-index in my JavaScript function by adding element.style.zIndex="1" or object.style.zIndex="1", and also set z-index:-1; in my YouTube CSS, but unfortunately, it hasn't resolved the problem. Can anyone suggest what steps I should take next?

YouTube CSS:

position: absolute;
height: 259px;
width: 683px;
left: 235px;
float: left;
text-align: right;
z-index: -1;

YouTube code:

<div id="youtube_video" style="float: right">
<object width="580" height="259" float="right"><param name="movie" value="http://www.youtube.com/v/7mKpzQOlyKE?fs=1&hl=iw_IL"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/7mKpzQOlyKE?fs=1&hl=iw_IL" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="580" height="259"></embed></object>

Answer №1

Try inserting wmode="opaque" into the parameters of the <object> / <embed> tags to determine if it provides any assistance.

Answer №2

This is a common issue that can easily be resolved. You can use a lightbox or something similar to address it. One way to handle this situation is by creating a function on the event start (when the lightbox is shown), where you hide the object, like so: (I've placed the YouTube video inside a div with the class name "ToHide")

$(".ToHide").hide(); 

Then, I recommend registering an event on the lightbox (on closed). When this event is triggered, you can show the hidden object using the following code:

$(".ToHide").show();

And that's all! Problem solved :)

Answer №3

The issue lies within the flash player, as it is programmed to operate in an overlay mode that does not take into account sorting or z-index.

To resolve this problem when embedding the flash object, you can include

<param name="wmode" value="opaque" />
in the code, or if using swfobject, use .addParam('wmode', 'opaque');

When dealing with YouTube videos, simply add wmode="opaque" to the embed element.

Answer №4

Discover how to resolve overlay and z-index issues with YouTube iframes by visiting the following link:

The main idea is...

Answer №5

<script language="javascript"> 
function playYouTube(id){ 
  //Customizing YouTube Player Settings 
  var width = 640; 
  var height = 505; 
  var FullScreen = "yes"; 
  var AutoPlay = "yes"; 
  var HighQuality = "yes";

  //Determining Page Dimensions 
  var pageWidth = window.innerWidth; 
  var pageHeight = window.innerHeight; 
  if (typeof pageWidth != "number"){ 
    if (document.compatMode == "CSS1Compat"){ 
      pageWidth = document.documentElement.clientWidth; 
      pageHeight = document.documentElement.clientHeight; 
    } else { 
      pageWidth = document.body.clientWidth; 
      pageHeight = document.body.clientHeight; 
    } 
  } 
  // Display Background 
  var background = document.getElementById('bg'); 
  background.style.visibility = "visible"; 

  //Creating a New Div for YouTube Popup 
  var divElement = document.createElement('div'); 
  divElement.setAttribute('id',id); 
  divElement.className = "popup"; 
  divElement.style.visibility = "visible"; 
  var divWidth = width + 4; 
  var divHeight = height + 20; 
  divElement.style.width = divWidth + "px"; 
  divElement.style.height = divHeight + "px"; 
  var divLeft = (pageWidth - divWidth) / 2; 
  var divTop = (pageHeight - divHeight) / 2 - 10; 
  divElement.style.left = divLeft + "px"; 
  divElement.style.top = divTop + "px"; 

  //Create Close Button Div 
  var closeButton = document.createElement('div'); 
  closeButton.style.visibility = "visible"; 
  closeButton.innerHTML = "<span onclick=\"closeYouTube('" + id +"')\" class=\"close_button\">X</span>"; 
  divElement.appendChild(closeButton); 

  //Create YouTube Video Div 
  var youtubeDiv = document.createElement('div'); 
  youtubeDiv.setAttribute('id', "yt" + id); 
  youtubeDiv.className = "ytcontainer"; 
  youtubeDiv.style.width = width + "px"; 
  youtubeDiv.style.height = height + "px"; 
  if (FullScreen == "yes") FullScreen="&fs=1"; else FullScreen="&fs=0"; 
  if (AutoPlay == "yes") AutoPlay="&autoplay=1"; else AutoPlay="&autoplay=0"; 
  if (HighQuality == "yes") HighQuality="&hd=1"; else HighQuality="&hd=0"; 
  var URL = "http://www.youtube.com/v/" + id + "&hl=en&rel=0&showsearch=0" + FullScreen + AutoPlay + HighQuality; 
  var YouTubeEmbed = "<object width=\"" + width + "\" height=\"" + height + "\">";
  YouTubeEmbed += "<param name=\"movie\" value=\"" + URL + "\"></param>";
  YouTubeEmbed += "<param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param>";
  YouTubeEmbed += "<embed src=\"" + URL + "\" type=\"application/x-shockwave-flash\" ";
  YouTubeEmbed += "allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"" + width + "\" height=\"" + height + "\"></embed></object>";
  youtubeDiv.innerHTML = YouTubeEmbed;
  divElement.appendChild(youtubeDiv);

  document.body.appendChild(divElement);
} 
function closeYouTube(id){ 
  var background = document.getElementById('bg'); 
  background.style.visibility = "hidden"; 
  var divElement = document.getElementById(id); 
  var youtubeDiv = document.getElementById("yt" + id); 
  divElement.removeChild(youtubeDiv); 
  document.body.removeChild(divElement);
} 
</script>

<style type="text/css"> 
.popup { position: absolute; z-index: 2; } 
.popup_bg { position: absolute; visibility: hidden; height: 100%; width: 100%; filter: alpha(opacity=70); opacity: 0.7; left: 0px; top: 0px; background-color: #999; z-index: 1; } 
.ytcontainer { border: 2px solid #666; clear: both; } 
.close_button { font-family: Verdana, Geneva, sans-serif; font-size: small; font-weight: bold; color: #666; text-decoration: none; display: block; float: right; background-color: #FFF; z-index: 3; cursor: default; border: 2px solid #666; margin-bottom: -2px; padding: 0px 3px 0px 3px; } 
body { margin: 0px; } 
</style>

and a link to play youtube video in popup

 <a href="#" onclick="playYouTube('_AJ0SkbPxAk')">Stewie Beats Brian</a>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to duplicate the geometrical shape within the scene?

I'm currently experimenting with Three.js to recreate a flower as part of my learning process for transformations. Below is the code I used to generate the stamen, stem, and petals. My goal is to have multiple petals stemming from the same Petal mesh ...

Design a dynamic tile grid layout using CSS Grid that adapts to different

I've recently started exploring the world of CSS Grid and I'm interested in creating a responsive tile-like layout using it. I found an example that I really like here: Do you think using CSS Grid is a good approach for achieving this type of la ...

Two separate projects targeting Admin and User interfaces versus a unified application featuring distinct themes for each user role

In React, there is a scenario that needs to be implemented. An admin panel with various functionalities like Auth, charts, analytics, and user management has already been pre-built. The goal now is to connect this admin panel to another website as the back ...

I encountered an issue while trying to integrate react-alert into my React application. An Uncaught Error was thrown, stating that objects are not valid as a React

I encountered the following error: react-dom.development.js:14748 Uncaught Error: Objects are not valid as a React child (found: object with keys {$$typeof, render}). If you meant to render a collection of children, use an array instead. in Unknown (c ...

Is it possible to log messages to the Selenium RC log using JavaScript in Selenium?

Seeking a way to log messages to Selenium RC's log using Javascript. For instance seleniumRc.log('Statement'); Wondering if it can be done? Appreciate any help! DashK ...

Setting up xlsx for converting Excel spreadsheets to JSON format

Here is the command sequence I used to attempt the xlsx installation : sudo npm install xlsx npm install xlsx sudo npm install excel --save-dev npm install excel --save-dev However, after running each of these commands I encountered a consistent error mes ...

Develop a list of findings from the search

Is there a way to extract the name from the image shown below? return testData.then((data) => { console.log(data) var results = []; var toSearch = params.suggestTerm; data = data["data"]["0"]; console.log(" ...

What could be the reason for the malfunction of the min value in my Material UI date textfield?

I am attempting to set a minimum date for the picker to start from, but it does not seem to be working as expected. <TextField id="date" type="date" defaultValue="2017-05-24" minDate="24/01/2019" ...

How do I retrieve the HSL value for a color selected using an input of type 'color' in JavaScript?

I am faced with a creativity block and don't know where to begin. My goal is to develop functions that can manipulate the HSL values once I have access to them. Specifically, I am interested in modifying the light value, which is why I require it in ...

Sending a parameter to an (internationally?) externalized class

Forgive me if this question seems convoluted - my grasp on the intricacies of module.export functionality and class scoping may be lacking, but I'll do my best to elaborate. At present, I possess a discord bot with a music player that incorporates a M ...

Using react-select to display "N items selected" instead of listing out all the selected items

Exploring the potential of react-select as a city-picker selector for users to choose one or multiple cities to filter data. Take a look at how it appears on my page: https://i.sstatic.net/A3cBX.png The list of cities may be extensive, and I am concerned ...

How come HTML fails to display an image sent through Express?

I have a remote server with an Express server that serves a tiger image at this link. The Express server code on the link is: var express = require('express'); var app = express(); app.use(cookieParser()) app.use(cors()) app.use(helmet()) app.us ...

Unable to associate JSON data using the map method

In the JSON example provided below, I am trying to extract the name of the genres. { "adult": false, "backdrop_path": "/5qxePyMYDisLe8rJiBYX8HKEyv2.jpg", "budget": 178000000, "genres": [ { "id": 12, "name": "Adventure" }, { ...

The focus of the input is lost when the value is being edited, specifically in the case where ngFor and ng

I'm facing an issue with a simple list that binds two-way to a parameter hero in my hero.component.ts. Whenever I begin typing in the input field, it seems to lose focus and I have to click on it again. How can I ensure that users are able to edit th ...

Blank advertisements displayed on WordPress due to Google AdSense malfunction

My website on Wordpress can be found at . I encountered issues with the deprecated Adsense plugin for WordPress, so I created my own Adsense account. After verifying my site, I created a new ad unit and inserted its code into the body tag. The code for my ...

Extracting input value using HTML and JavaScript

Is there a way to utilize the content of a form field within a confirmation dialog box that pops up upon submission, as illustrated below? <form action='removefinish.php' method='post' accept-charset='UTF-8'> Role: < ...

Issue with CSS causing dropdown to open underneath modal

I am facing an issue with my bootstrap modal that contains multiple dropdowns. To accommodate the content, I have set overflow: auto to enable a scroll bar on the right side of the modal. The problem arises when I click on a dropdown - it opens under the ...

Summernote - Add Text while maintaining formatting requirements

Currently, I am facing an issue where inserting a string of text from a dropdown list into the Summernote text editor results in the closing of formatting tags such as <'strong'>, <'p'>, and more. After inserting the string ...

Angular 4 in combination with ngx-datatable is showing a 404 error for the @swimlane/ngx-datatable package

Just starting out with Angular and I kicked things off by running this command: git clone https://github.com/angular/quickstart appName I've made the upgrade to Angular 4 and everything seems to be in order. Here's the output I got after running ...

Removing information from a database using the delete function

I'm currently facing an issue while trying to delete an item from the database using a button that calls a delete function. Everything seems to be working fine, and I can see the API call for deletion in the console. However, the req.body is coming up ...