Get id from url in javascript
Posted: 03 May 2019, 20:27
Last time you learnt me how to add an id from url to a javascript
but by this script it is not working what do I do wrong ????
this is the demo script demo.js
// Set the id of the video to be played
videoId: '+id_usr',
I try to get this kind off id from url: Player/Video.php?id=Sj2GVab9nOo
Please help.
but by this script it is not working what do I do wrong ????
Code: Select all
<?php
include('../connection.php');
$id = isset($_GET['id']) ?(int) $_GET['id'] :'';
//your code ..
?>
<!DOCTYPE html>
<html>
<head>
<!-- page title -->
<title>YouTube in Your App</title>
<!-- Style imports for Material Design Lite -->
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.indigo-pink.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- This code loads the iFrame Player API code asynchronously.-->
<script src = "//www.youtube.com/iframe_api"></script>
<!-- This is the source of the Javscript for the demo -->
<script>
var id_usr ='<?php echo $id; ?>';
</script>
<script src="demo.js"></script>
</head>
<body>
<!-- Header -->
<main class="mdl-layout__content">
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--5-col">
<!-- The iframe video player will replace this <div> tag. -->
<div id="player"></div>
</div>
this is the demo script demo.js
Code: Select all
var id_usr ='$_GET["id"]';
var player;
// Callback for when the YouTube iFrame player is ready
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
// Set Player height and width
height: '390',
width: '640',
// Set the id of the video to be played
videoId: '+id_usr',
// Setup event handelers
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange,
'onPlaybackQualityChange': onPlaybackQualityChange,
'onPlaybackRateChange': onPlaybackRateChange,
'onError': onError,
'onApiChange': onApiChange,
}
});
};
videoId: '+id_usr',
I try to get this kind off id from url: Player/Video.php?id=Sj2GVab9nOo
Please help.