I am having trouble embedding YouTube videos with my code

Need a fresh pair of eyes on this code. Everything looks correct to me, but it's not functioning as expected. The entries are results from a search.


function displayVideos(data) {
    var feed = data.feed;
    var entries = feed.entry || [];

    var html = ['<ul>'];
    for (var i = 0; i < entries.length; i++) {
        var entry = entries[i];
        var playCount = entry.yt$statistics.viewCount.valueOf() + ' views';
        var title = entry.title.$t;
        var lnk = '<a href="' + entry.link[0].href + '">link</a>';
        var entPar = objToString(entry.id);
        var parseEntries = entPar.split("/");
        var videoID = parseEntries[5].substring(0,11)
        var params = { allowScriptAccess: "always" };
        var atts = { id: "ytPlayer" };

        // SWFObject handles the embedding
        swfobject.embedSWF("http://www.youtube.com/v/" + videoID + "?version=3&enablejsapi=1&playerapiid=player1", "videoDiv", "480", "295", "9", null, null, params, atts);

        html.push('<li>', title, ', ', playCount, ', ', lnk, '</li>');
    }
    html.push('</ul>');
    document.getElementById('videoResultsDiv').innerHTML = html.join('');
}

Answer №1

I'm not familiar with swfobject, but based on what I can tell, it seems like you have generated a swf object and are requesting it to be inserted into the videoDiv element. Are you certain that this is the desired action?

From my perspective, it appears that you should have utilized the createSWF method and included the resulting object in your html array instead.

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

Having trouble with NextJS when trying to add an item to an element and render it in a Tailwind select

Struggling with displaying dynamic values in a select box using NextJS After fetching data from an API endpoint, I aim to populate a select box. However, my goal is to prepend a new element to the 'teams' array and ensure it appears first upon p ...

Switch the array's value if the key is a match?

I'm currently facing an issue where my code does not push the object when the key matches. How can I update the value of the key instead when there is a match? this.state.data.concat(items).filter(function (a) { return !this[a.key] && (th ...

Generating Unique Random DIV IDs with JavaScript

Does anyone know of a JavaScript solution to generate unique random DIV IDs? I am currently using PHP for this purpose. <?php function getRandomWord($len = 10) { $word = array_merge(range('a', 'z'), range('A', &apos ...

Opposite path matching with Next.js middleware

For my Next.js project, I have implemented a middleware and now I need it to only apply to routes that do not start with /api/. I have checked the documentation but couldn't find a similar example. Is there a way to achieve this without manually excl ...

Optimal approach for storing objects in cache

I'm currently utilizing Redis as a cache service (Key=>Value) within AWS ElastiCache. My goal is to store an object that contains nested objects inside the cache: Object1 - which includes an instance of Object2 Before saving the object, I seria ...

The JavaScript "sort()" method outlined in the Mozilla Documentation specifically created for the sorting of numbers

When it comes to sorting numbers in JavaScript, we can utilize the sort() function with a specific trick that yields perfect results. The tip for successful number sorting is as follows: [12, 2, 23, 3, 43, 54].sort(function (a, b) { return a - b ; } ) S ...

What is the connection between importing and using destructuring in ES6 syntax?

Bring in: import React, { Component } from 'react'; Unpacking: let z, { b } = {a: 1, b: 2, c: 3} Both of these examples seem to have similar syntax. However, in the second example, z will be undefined instead of {a: 1, b: 2, c: 3}. Does this ...

Utilizing React Router with Material-Table for Efficient Column Value Filtering

Is there a way to dynamically pass Route params into the filtering fields of a React table component? I am currently utilizing the material-table component and have a list of links structured like this: <ul> <li> <Link to="/Products/ ...

Error: The function "navigate" has not been declared or defined

Just starting out in reactjs and embarking on a new project. I've successfully implemented a register and login function using firebase, but hit a snag when trying to navigate to a new page like the dashboard upon user login, I encountered this error: ...

What is the proper way to invoke a function that is part of a child component as a property in a React application?

In my app.js file, I have included a unique component called "SigningComponent" with the following code: onSign = () => { this.setState({ route: "home" }); }; registerFunction = () => { this.setState({ route: "registration" }); }; render() { ...

A guide on extracting values from a PHP database in Json format

In my project, I need to implement a Matrix tree view using JSON. I am planning to fetch PHP values in JSON format. Can anyone guide me on how to achieve this? Currently, I have a static matrix tree structure but I want it to be dynamic. Thank you in advan ...

What are some ways to utilize symbol fonts such as marvosym within a web browser?

Are you looking to use special LaTeX fonts like \Pluto from marvosym in your web development projects? Wondering how to display this symbol with HTML / JavaScript / CSS without relying on an image? You can download the font from This symbol corresp ...

PHP is adding unique characters like   into the database records

Description : Having an issue with adding a text to a content editable div. When clicking the button, I am trying to extract all the text from the div and send it to php successfully. However, when saving it to my database table, the text gets corrupted. A ...

I'm facing an issue where there is no "Access-Control-Allow-Origin" header present. Looking for assistance in converting it to JSONP using the POST method. Can anyone provide guidance?

Even though I have changed it to JSONP, the CORS error is still persisting. Here is the updated code snippet: $.ajax({ type: "POST", url: "<a href="https://api.api.ai/v1/" rel="nofollow noreferrer">https://api.api.ai/v1/</a& ...

What are the ideal scenarios for utilizing Dynamic encoding/decoding in Swift?

I am new to coding in Swift and I'm feeling a little confused about the concept of dynamic encoding and decoding. During an interview, I was asked to parse the response from an API. The API response looks like this: { "propertyID" : 12, "us ...

What type of Javascript is required for a photo carousel that displays random images from a designated folder?

I have a minor issue that has been keeping me up at night. I can't seem to shake it off and find the right solution! Currently, I am working with Bootstrap 4 as my Framework. My task is to create a full-page Carousel that cycles through images random ...

There appears to be an issue with the server, as it is reporting a TypeError with the _nextProps.children property not

As a newcomer to coding, this is my first question on the forum. I appreciate your understanding and patience as I navigate through some challenges. I'm currently working on making my NextJS SSR app responsive, but after modifying the index.js and ot ...

Minimizing repeated autofocus calls in material-ui's <TextField> component

In the realm of coding with material-ui, when dealing with the <TextField> component, it's important to keep in mind that the solution may actually lie within React itself. Let's paint a scenario where we're crafting a basic login for ...

Ways to differentiate between an angular element and a jQuery element

In order to implement a feature where clicking outside of a dropdown hides it within a directive, I have the following code: $(document).click(function(e) { var selector = $(e.target).closest('.time-selector'); if (!selector. ...

Converting XML to Json with the help of Json-lib

Currently, I'm working on an Android project where I need to convert an XML document from a web source into JSON format. This is the approach I've taken: URL url; InputStream in; try { url = new URL("http://www.aemet.es/xml/municipios/loca ...