0

I'm trying to make a watch page like the YouTube watch page.

Example of YouTube watch page URL: /watch?v=J3atcU_7yxA
Example of my watch page URL: /watch/?s=mindfield&e=isolation

I'm trying to achieve that with this JavaScript code:

var url = new URL(document.URL);
var s = url.searchParams.get("s");
var e = url.searchParams.get("e");

if (s == "mindfield" && e == "isolation") {
  player('https://youtube.com/embed/iqKdEhx-dD4');
};

function player(source) {
  document.getElementsByTagName("iframe")[0].setAttribute("src", source);
}

But it's just not working and I don't know why!

If you would like here is the website of where I'm trying to achieve that.

Thank you!

  • You should probably remove that link and then not link that page to any else. The content you are showing _(as I'm sure you are aware)_ are property of youtube _(youtube-red)_ and sharing it would probably be considered an illegal action. – Olian04 Dec 16 '17 at 15:42
  • What do you mean with "it's not working". The player loads with the link provided in the `if`. – yuriy636 Dec 16 '17 at 15:44
  • @yuriy636 I changed the embed video to [this](https://youtu.be/J3atcU_7yxA) so if you access the website with these parameters (?s=mindfield&e=isolation) you should get [this](https://youtu.be/iqKdEhx-dD4) – Bernardo Silva Dec 16 '17 at 16:01
  • Possible duplicate of [setAttribute('src','page.html') is not working](https://stackoverflow.com/questions/15574305/setattributesrc-page-html-is-not-working) – yuriy636 Dec 16 '17 at 16:17

0 Answers0