Jump to content

Javascript stopped working with <video>....


612wharfavenue

Recommended Posts

Ive been working with this simple script for a while now so that video would play onclick:

//headercrapomitted//<html><head><style>#video {}</style><script type="text/javascript">var v = document.getElementById("video");v.onclick = function () {			  v.play();};</script></head><body><video src="myvideo.webm" id="video" /></body></html>

Today it has suddenly stopped working. Ive created a new page just to make it work and nothing, video plays fine however. Tested on both opera and FF4. Ive reinstalled both browsers and java (or whatever). Im getting a bad case of the fuc-its, what the ###### is going on.

Link to comment
Share on other sites

Ive been working with this simple script for a while now so that video would play onclick:
//headercrapomitted//<html><head><style>#video {}</style><script type="text/javascript">var v = document.getElementById("video");v.onclick = function () {			  v.play();};</script></head><body><video src="myvideo.webm" id="video" /></body></html>

Tested on both opera and FF4. Ive reinstalled both browsers and java (or whatever). Im getting a bad case of the ######its, what the ###### is going on.

I think video's will play on their own if you click the play button? You can add controls to a video tag to make those controls show up. As far as I know, there isn't a play method in javascript. Did you find documentation about it online somewhere? Maybe you can add the autplay property to a video tag with an empty src, and when it get's clicked on, you might be able to then load the source and it could start playing automatically, but then why not just use the play button?edit: actually, have you tried it as Play?
Link to comment
Share on other sites

also, it's because you're trying to get the id of an element before it's been loaded into the DOM. You should either put the script tags after the video element on the page, or put the function inside window.onload or document.ready.

Link to comment
Share on other sites

I see, putting it after the video element does work, even though i never had to do that before. This is the second time ive come back to my computer and found the script i had verified as working no longer did. How often does javascript change its own functionality? I dont even see the point of trying if the platform im working on suddenly shifts itself and destroys my work.

Link to comment
Share on other sites

I followed this example and made it an external script that i called but it doesnt workhttp://www.learningjquery.com/2006/09/intr...-document-ready

 "http://www.w3.org/TR/html4/strict.dtd"><html lang="en"><head>  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>  <title>your title</title>  <link rel="stylesheet" type="text/css" href="styles/forms.css"></link>  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>  <script src=$(document).ready("play.js")  type="text/javascript"></script></head><body>  <!-- the body of your document goes here --></body></html>

Link to comment
Share on other sites

ok ###### jquery, taking window.onload straight from here https://developer.mozilla.org/en/DOM/window.onload i get:

<script type="text/javascript">var v = document.getElementbyId("video");			 window.onload = function () {				 v.onclick = function () {			   v. play();};	   };</script>

Still doesnt work. Id cant tell whether js is constantly changing in the background or everyone on the net is bull######ting me, but its looking like a mixture of both.

Link to comment
Share on other sites

This line: var v = document.getElementbyId("video"); has to go inside the window.onload event handler as well. No use trying to assign an element that doesn't exist yet.P.S. JavaScript does change that fast :).

Link to comment
Share on other sites

ok ###### jquery, taking window.onload straight from here https://developer.mozilla.org/en/DOM/window.onload i get:
<script type="text/javascript">var v = document.getElementbyId("video");			 window.onload = function () {				 v.onclick = function () {			   v. play();};	   };</script>

Still doesnt work. Id cant tell whether js is constantly changing in the background or everyone on the net is bull######ting me, but its looking like a mixture of both.

you're supposed to use window.onload or document.ready as a wrapper, to ensure code is only executed after the document has fully finished loading, and the complete DOM tree is available. Still doing getElementById before that happens is pretty much the same thing you were doing. If you are using jQuery, then you can do it like this:
<script type="text/javascript>$(document).ready(function(){   var v = document.getElementbyId("video");  v.onclick = function () {	v. play();  };};</script>

http://docs.jquery.com/Tutorials:Introduci...%29.ready%28%29

Link to comment
Share on other sites

Or (with fixed bracketing too):

$(document).ready(function() { 	$("#video").bind("click", function() {		this.play();	});});

Link to comment
Share on other sites

Or (with fixed bracketing too):
$(document).ready(function() { 	$("#video").bind("click", function() {		this.play();	});});

think you're soooo fancy.... :)
Link to comment
Share on other sites

I see, putting it after the video element does work, even though i never had to do that before. This is the second time ive come back to my computer and found the script i had verified as working no longer did. How often does javascript change its own functionality? I dont even see the point of trying if the platform im working on suddenly shifts itself and destroys my work.
That doesn't happen. The computer is not a magic box. The script you posted originally never works, in any browser. There is a slight modification to that script which would cause it work, which is wrapping the code in a window.onload event like people showed (or moving the code in the body). I understand your frustration with learning this stuff, but just keep in mind that the computer only does what you tell it to do, it doesn't make any decisions on its own. The binary language it understands has 2 values, true and false. There's no value for "maybe" or "random" or anything else.The only time you're going to run into Javascript code that stops working or changes how it works is when you download a new browser version and they either fixed the bugs you were relying on or changed their old code to match what everyone else is doing.
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...