-4
<script type="text/javascript">
    //GET DATA FROM URL ...index.html?PageTitle,YOUTUBE_ID
    var DATA = window.location.search.replace("?", "");
    //STORE IN ARRAY FOR EASY ACCESS AND EXPANDABILITY
    DATA = DATA.split(",");
    //LOAD THE PAGE TITLE
    document.title = DATA[0]
    //UPDATE THE IFRAME SRC AFTER THE DOCUMENT LOADS
    window.onload = function() {
        var YouTube = document.getElementById('YouTube');
        YouTube.src = "http://www.youtube.com/embed/" + DATA[1]
    };
</script>
 <div class='content'>
     <iframe id="YouTube" width="853" height="480"
 frameborder="0" allowfullscreen>
 </div>

I've got this code above, which allows me to change my websites embedded video depending on what the user inputs in the url.

The standard url goes www.mysite.com/index.html/?, and then obviously the video code on the end.

How could I rewrite this code so there is no comma after the question mark?

or if possible no question mark at all so just www.mysite.com/index.html/videocode

NOTE: the comma is intentional in the standard url example.

4

2 回答 2

1

The same script, modded:

<script type="text/javascript">
    //GET DATA FROM URL ...index.html?YOUTUBE_ID
    var DATA = window.location.search.replace("?", "");
    //UPDATE THE IFRAME SRC AFTER THE DOCUMENT LOADS
    window.onload = function() {
        var YouTube = document.getElementById('YouTube');
        YouTube.src = "http://www.youtube.com/embed/" + DATA;
    };
</script>

You might want to learn a little more about URL's to achieve your last goal (of removing the question-mark).
Then look into url-rewrite and serverside-scripting to achieve:

www.mysite.com/index.html/videocode = www.mysite.com/index.php/videocode = www.mysite.com/videocode
于 2013-03-31T01:33:40.350 回答
0

You can use some Javascript to remove the last character of a string. In effect, removing your comma symbol.

var foo = "www.google.com/,";
foo = foo.substring(0, foo.length - 1);
console.log(foo); // "www.google.com/"
于 2013-03-31T01:19:34.087 回答