-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>

上記のコードを使用すると、ユーザーが URL に入力した内容に応じて、Web サイトに埋め込まれたビデオを変更できます。

標準の URL が続きwww.mysite.com/index.html/?,、最後にビデオ コードが表示されます。

疑問符の後にコンマがないように、このコードを書き直すにはどうすればよいですか?

または、可能であれば疑問符がまったくないので、www.mysite.com/index.html/videocode

注: 標準の URL の例では、コンマは意図的なものです。

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

Javascript を使用して、文字列の最後の文字を削除できます。実際には、コンマ記号を削除します。

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