Jump to content

get info from URL and set as a javascript variable


jarvis

Recommended Posts

That doesn't do anything either:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script>
alert(html);
</script>
</head>

<body>
</body>
</html>

Appreciate this! I feel such a noob

Here's my complete js just incase I've missed something:

//-------------------------------------------------
//		youtube playlist jquery plugin
//		Created by [email protected]
//		www.geckonewmedia.com
//
//		v1.1 - updated to allow fullscreen 
//			 - thanks Ashraf for the request
//-------------------------------------------------

jQuery.fn.ytplaylist = function(options) {

  // default settings
  var options = jQuery.extend( {
    holderId: 'ytvideo',
playerHeight: '258',
playerWidth: '399',
addThumbs: false,
thumbSize: 'small',
showInline: false,
autoPlay: true,
showRelated: true,
allowFullScreen: false
  },options);
  
  return this.each(function() {

   		var selector = $(this);
	var autoPlay = "";
	var showRelated = "&rel=0";
	var fullScreen = "";
	if(options.autoPlay) autoPlay = "&autoplay=1"; 
	if(options.showRelated) showRelated = "&rel=1"; 
	if(options.allowFullScreen) fullScreen = "&fs=1"; 

	//throw a youtube player in
	function play(optionVars) {
		var options   = optionVars.split('|');
		var id        = options[0];
		var urlType   = options[1];
		//alert(options);
		//alert(urlType);
		var html  = '';
		html += '<object height="'+options.playerHeight+'" width="'+options.playerWidth+'">';
		html += '<param name="movie" value="http://www.'+urlType+'.com/v/'+id+autoPlay+showRelated+fullScreen+'"> </param>';
		html += '<param name="wmode" value="transparent"> </param>';
		if(options.allowFullScreen) { 
			html += '<param name="allowfullscreen" value="true"> </param>'; 
		}
		html += '<embed src="http://www.'+urlType+'.com/v/'+id+autoPlay+showRelated+fullScreen+'"';
		if(options.allowFullScreen) { 
			html += ' allowfullscreen="true" '; 
		}
		html += 'type="application/x-shockwave-flash" wmode="transparent"  height="'+options.playerHeight+'" width="'+options.playerWidth+'"></embed>';
		html += '</object>';
		return html;
	};

	//grab a youtube id from a (clean, no querystring) url (thanks to http://jquery-howto.blogspot.com/2009/05/jyoutube-jquery-youtube-thumbnail.html)
	function youtubeid(url) {
		var ytid = url.match("[\\?&]v=([^]*)");
		var regex  = /(facebook|youtube)/i;
		var type   = regex.exec(url);
			ytid = ytid[1];
			return ytid + '|' + type[0];

	};


	//load inital video
	var firstVid = selector.children("li:first-child").addClass("currentvideo").children("a").attr("href");
	$("#"+options.holderId+"").html(play(youtubeid(firstVid)));

	//load video on request
	selector.children("li").children("a").click(function() {

		if(options.showInline) {
			$("li.currentvideo").removeClass("currentvideo");
			$(this).parent("li").addClass("currentvideo").html(play(youtubeid($(this).attr("href"))));
		}
		else {
			$("#"+options.holderId+"").html(play(youtubeid($(this).attr("href"))));
			$(this).parent().parent("ul").find("li.currentvideo").removeClass("currentvideo");
			$(this).parent("li").addClass("currentvideo");
		}



		return false;
	});

	//do we want thumns with that?
	if(options.addThumbs) {

		selector.children().each(function(i){
										  
			var replacedText = $(this).text();

			if(options.thumbSize == 'small') {
				var thumbUrl = "http://img.youtube.com/vi/"+youtubeid($(this).children("a").attr("href"))+"/2.jpg";
			}
			else {
				var thumbUrl = "http://img.youtube.com/vi/"+youtubeid($(this).children("a").attr("href"))+"/0.jpg";
			}


			$(this).children("a").empty().html("<img src='"+thumbUrl+"' alt='"+replacedText+"' />"+replacedText).attr("title", replacedText);

		});	

	}


   
  });

};

Odd yours works and mine wont so guessing I've not set something perhaps?

Thats ok, sorry!

I just can't see why it wont work, especially as you say your one does! Just frustrating as I never thought this would turn out to be such a mare!

I do really appreciate your help though, especially as you're at work! :-)

So how do you get the selected video from user? From click of a link or? This example uses the click event to determine the video type.

 

<html>
<head>
	<title></title>
	<script type="text/JavaScript" src="../js/jquery-ui-1.8.13.custom/js/jquery-1.5.1.min.js"></script>
	<script type="text/JavaScript">
	$(document).ready(function() {

		// For click event
		$('ul.demo li a').click(( function(event) {
			event.preventDefault(); // To prevent redirecting to the link location.
			var URL = $(this).attr('href');
			if (URL.match('/.*youtube.*/'))
			{
				// Link was youtube video, do something..
			}
			else if (URL.match('/.*facebook.*/'))
			{
				// Link was facebook video, do something..
			}
			else
			{
				// Something else..
			}
		}));
	});
	</script>
</head>
<body>
	<!-- video library -->
	<ul class="demo">				
	<li><a href="http://www.facebook.com/#!/video/video.php?v=123">Video 1</a></li> 	
	<li><a href="http://www.facebook.com/#!/video/video.php?v=456">Video 2</a></li>
	<li><a href="http://www.facebook.com/#!/video/video.php?v=789">Video 3</a></li> 	
	<li><a href="http://www.youtube.com/watch?v=w0ffwDYo00Q">Video 4</a></li>  															
	</ul>
	<!-- video library -->

</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.