Jump to content

Command line arguments


dudemike

Recommended Posts

I wrote a small HTML page to play some videos. I wrote a small java script to fetch my command line paramenters, but am totally lost how to pull them from the java script down into the object/embed code. The code I am enclosing below works. If I move the </script> line below the object/embed line, nothing works. Any ideas? Mike.

 

 

 

<head><style>body{background-image:url("opaq.jpg"); background-repeat: repeat;background-position: left top;}td { text-align: center;}</style></head> <table border="0" style="margin-left: 125px;"><tr> <td height="200"><a href="junk.html?pic=v1.jpg&vid=vid1.avi"><img tabindex="0" src="v1.jpg"></a></td> <td height="200"><a href="junk.html?pic=v2.jpg&vid=vid2.avi"><img tabindex="0" src="v2.jpg"></a></td> <td height="200"><a href="junk.html?pic=v3.jpg&vid=vid3.avi"><img tabindex="0" src="v3.jpg"></a></td></tr><tr> <td colspan="3"><script type="text/javascript"> // yo bro, this is my command line: // vid.html?pic=(v1.jpg||v2.jpg||v3.jpg)&vid=(vid1.avi||vid2.avi||vid3.avi) // // Skip the 1st character, we are not interested in the "?" var query = location.search.substring(1); // split the rest at each "&" character to give a list of "argname=value" pairs var pairs = query.split ("&"); // break 1st pair at the first "=" to obtain the argname and value var pos0 = pairs [0].indexOf("="); var pos1 = pairs [1].indexOf("="); var picname = pairs[0].substring(pos0+1); var vidname = pairs[1].substring(pos1+1);document.write("<p>hello world 1</p>"+ "<br>");document.write(picname + "<br>");document.write(vidname + "<br>");document.write("<p>hello world2</p>"+ "<br>");</script><object classid="clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616" width="1280" height="740" codebase="http://go.divx.com/plugin/DivXBrowserPlugin.cab"> <param name="custommode" value="none" /> <param name="previewImage" value="v1.jpg" /> <param name="autoPlay" value="false" /> <param name="src" value="vid1.avi" /><embed type="video/divx" src="vid1.avi" custommode="none" width="1280" height="740" autoPlay="false" previewImage="v1.jpg" pluginspage="http://go.divx.com/plugin/download/"></embed></object> </td></tr></table>

Link to comment
Share on other sites

First, remove all of the document.write lines, you shouldn't use document.write. If you want to output debugging information then use console.log, and check your browser's developer console for the messages.You'll need to move the code below the object and embed elements, or set the code to run after the page is loaded. If you try to modify those elements from that code as it is now then the elements won't exist yet, the browser hasn't gotten to them.I'm not sure how well it is going to work to modify the existing elements on the page. You might want to create the embed and object elements inside Javascript, assign the necessary parameters to them, and then add them to the page programmatically. You could try giving the necessary elements IDs and access them via ID to update the src or whatever you want to change, but like I said I'm not sure whether that would work to cause it to play the new video. It would be better to create the elements and add them to the page with Javascript.You could also change the code that checks the querystring to check the names of each parameter that was passed so that you can pass them in any order instead of expecting pic first and vid second.

Link to comment
Share on other sites

What you have posted looks like a fragment of a page. Did you only post a part of what you have?

 

What you are doing inserting and then extracting URL parameters makes no sense for this -- where did you see that used?

 

If you have an HTML tag...

 <param name="src" value="vid1.avi" id="videofilename" />

...then in the script you can simply declare a function such as...

function vidsel( vid ) {document.getElementById('videofilename').value = vid;}

...and you can call the vidsel() function with a button like in this example...

 

http://www.w3schools.com/js/tryit.asp?filename=tryjs_function2

Link to comment
Share on other sites

I tried to pull my java script subroutines into a script, and call them from the object/embed sequence on top, but I must be messing up miserably ..... probably not even getting into my scripts. Any ideas how to pull those 2 js subroutines in? Tkx.

 

<head><style>body{background-image:url("opaq.jpg"); background-repeat: repeat;background-position: left top;}td { text-align: center;}</style></head> <table border="0" style="margin-left: 125px;"><tr> <td height="200"><a href="junk2.html?pic=v1.jpg&vid=vid1.avi"><img tabindex="0" src="v1.jpg"></a></td> <td height="200"><a href="junk2.html?pic=v2.jpg&vid=vid2.avi"><img tabindex="0" src="v2.jpg"></a></td> <td height="200"><a href="junk2.html?pic=v3.jpg&vid=vid3.avi"><img tabindex="0" src="v3.jpg"></a></td></tr><tr> <td colspan="3"> <object classid="clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616" width="1280" height="740" codebase="http://go.divx.com/plugin/DivXBrowserPlugin.cab"> <param name="custommode" value="none" /> <param name="previewImage" value="Javascript:GetPicName()" /> <param name="autoPlay" value="false" /> <param name="src" value="Javascript:GetVidName()" /><embed type="video/divx" src="Javascript:GetVidName()" custommode="none" width="1280" height="740" autoPlay="false" previewImage="Javascript:GetPicName()" pluginspage="http://go.divx.com/plugin/download/"></embed></object> <script type="text/javascript">function GetPicName(){ // yo bro, this is my command line: // vid.html?pic=(v1.jpg||v2.jpg||v3.jpg)&vid=(vid1.avi||vid2.avi||vid3.avi) // // Skip the 1st character, we are not interested in the "?" var query = location.search.substring(1); // split the rest at each "&" character to give a list of "argname=value" pairs var pairs = query.split ("&"); // break 1st pair at the first "=" to obtain the argname and value var pos0 = pairs [0].indexOf("="); var picname = pairs[0].substring(pos0+1);document.write(picname + "<br>"); return picname; }function GetVidName(){ var pairs = query.split ("&"); var pos1 = pairs [1].indexOf("="); var vidname = pairs[1].substring(pos1+1);document.write(vidname + "<br>"); return vidname;}</script></td></tr></table>

 

 

Link to comment
Share on other sites

I would really recommend just creating those elements in Javascript. Not all browsers support object or embed elements, for example, so instead of trying to modify those in an environment that might not support it, I would create the entire HTML markup as a string, with the values from the querystring inserted, and then add that HTML to the page by setting the innerHTML property of another element.

Link to comment
Share on other sites

That seems reasonable. As it is now he seems to have a mish-mash of html5 and html4 that doesn't clean up easily.

 

This won't validate as HTML5 or HTML4...

<!DOCTYPE HTML><html><head><title>tab</title></head><body><object classid="clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616" width="1280" height="740" codebase="http://go.divx.com/p...owserPlugin.cab"> <param name="custommode" value="none" > <param name="previewImage" value="v1.jpg" > <param name="autoPlay" value="false" > <param name="src" value="vid1.avi" > <embed type="video/divx" src="vid1.avi" custommode="none" width="1280" height="740" autoPlay="false" previewImage="v1.jpg" pluginspage="http://go.divx.com/plugin/download/"></object></body></html>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...