2016-04-06 2 views
2

私はフラッシュギャラリーのサイトを作っています。私は、ページの下部にあるテキストをフラッシュのダウンロードリンクにしたいと思います。このテキストは、現在表示されている現在のフラッシュのタイトルに変わります。 hrefタグを動的に変更して、ユーザーがダウンロードできるように再生中の特定のフラッシュのファイルパスに一致させたいと思います。これは、変数を使って動的に変化するものだけでなく、ダウンロードリンクを使って遊んだのは初めてです。ですから、私はリンクをリンク配列内に存在するファイルパスに変更したいと思います。ダイナミックリンクのための私の開始コードが含まれていますjavascriptを使って動的に変更するダウンロードリンクを作成するには?

機能は、私はそれをsloved、これは私のために働いているがDOWNLOAD

HTML

<body> 

    <div id="titleText"> 
     <h1>Anon Curb</h1> 
    </div> 
    <div id="flashmovie"> 
     <object type="application/x-shockwave-flash" data="swfs/welcomeflash.swf">'+ 
      <param name="movie" value="swfs/welcomeflash.swf"> 
     </object> 
    </div> 
    <!-- end #container --> 
    <div id="buttonCon"> 

     <div id="buttons"> 
      <button id="next">next</button> 

      <button id="rand">Random</button> 

      <button id="back">Back</button> 
     </div> 

    </div> 

    <div id="titleCon"> 
     <a href="#" id="downLink"> 
     <div id="title">Hit random button</div> 
     </a> 
    </div> 
    <!-- end #wrapper --> 

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js"></script> 
    <script src="js/flashcollection.js"></script> 
</body> 

JAVASCRIPT

$(document).ready(function() { 
    var links = [ 
'swfs/#1%20(Special%20Japanese%20Extended%20Dance%20Mix).swf', 
'swfs/$D6.swf', 
'swfs/(MAD)%20Huh.swf' 
]; 

var displaytext = [ 
'#1 (Special Japanese Extended Dance Mix)', 
'$D6', 
'(MAD) Huh' 
]; 

var c = 0 
    var flashmovie, test, temp; 

    function init() { 
     flashmovie = document.getElementById('flashmovie'); 
     document.getElementById('back').onclick = function() { 
      if (c == 0) { 
       c = links.length; 
      } 
      c-- 
      displayFiles(); 
     } 

     document.getElementById('next').onclick = function() { 
      if (c == links.length - 1) { 
       c = -1; 
      } 
      c++; 
      displayFiles(); 
     } 

     document.getElementById('rand').onclick = function() { 
      temp = c; 
      while (c == temp) { 
       c = Math.floor(Math.random() * links.length); 
      } 
      displayFiles(); 
     } 
    } 

    function displayFiles() { 

     test = links[c].substring(links[c].lastIndexOf('.') + 1, links[c].length); 
     document.getElementById('title').innerHTML = displaytext[c]; 

     flashmovie.innerHTML = 
      '<object type="application/x-shockwave-flash" data="' + links[c] + '">' + 
      '<param name="movie" value="' + links[c] + '">' + 
      '<\/object>'; 
    } 

    function download() { 
     document.getElementById('rand', 'back', 'next').onclick = function() { 
      document.getElementById('downlink').attr("href", links[c]); 
     } 
    } 

    window.addEventListener ? 
     window.addEventListener('load', init, false) : 
     window.attachEvent('onload', init); 
}); 

答えて

1

正しいjavascriptの

これはSoltaniネジの編集されたダウンロード機能を使用するだけでなく、時ダウンロード属性を変更するには、それなしでは動作しません。私にはその通常または特別な場合はフラッシュを作るフラッシュ消える以外は対応がとても時間がかかりますが、私は自分のコードをimplimentsとき、ちょうどタイトルを作るように見えた、ボタンについてSRYねえ

var c = 0; 
    var flashmovie, test, temp; 

    function init() { 
     flashmovie = document.getElementById('flashmovie'); 
     document.getElementById('back').onclick = function() { 
      if (c == 0) { 
       c = links.length; 
      } 
      c-- 
      displayFiles(); 
      download(); 
     } 

     document.getElementById('next').onclick = function() { 
      if (c == links.length - 1) { 
       c = -1; 
      } 
      c++; 
      displayFiles(); 
      download(); 
     } 

     document.getElementById('rand').onclick = function() { 
      temp = c; 
      while (c == temp) { 
       c = Math.floor(Math.random() * links.length); 
      } 
      displayFiles(); 
      download(); 
     } 

    } 

    function displayFiles() { 

     test = links[c].substring(links[c].lastIndexOf('.') + 1, links[c].length); 
     document.getElementById('title').innerHTML = displaytext[c]; 

     flashmovie.innerHTML = 
      '<object type="application/x-shockwave-flash" data="' + links[c] + '">' + 
      '<param name="movie" value="' + links[c] + '">' + 
      '<\/object>'; 
    } 

    function download() { 
     document.getElementById('downLink').setAttribute('href', links[c]); 
     document.getElementById('downLink').setAttribute('download', displaytext[c]); 
    } 

    window.addEventListener ? 
     window.addEventListener('load', init, false) : 
     window.attachEvent('onload', init); 
}); 
1

こんにちはと呼ばれる HTMLファイルの場合は、最初の画像のhrefを追加するだけで済みます。なぜなら、ファイルが最初に読み込まれるときにファイルが読み込まれ、 Oタグにattributのダウンロードを追加しますので、これはJavaScriptが

<div id="titleCon"> 

    <a href="unknittingmouse1.swf" id="downLink" download=""> 
    <div id="title">Hit random button</div> 
    </a> 
</div> 

ようになり、あなたはこの のようなダウンロード機能を編集して、すべてのボタンクリックイベントでそれを呼んで、このようなとしてする必要があります。

助け:)
$(document).ready(function() { 
    var links = [ 
'swfs/#1%20(Special%20Japanese%20Extended%20Dance%20Mix).swf', 
'swfs/$D6.swf', 
'swfs/(MAD)%20Huh.swf' 
]; 

var displaytext = [ 
'#1 (Special Japanese Extended Dance Mix)', 
'$D6', 
'(MAD) Huh' 
]; 

var c = 0 
    var flashmovie, test, temp; 

    function init() { 
     flashmovie = document.getElementById('flashmovie'); 
     document.getElementById('back').onclick = function() { 
      if (c == 0) { 
       c = links.length; 
      } 
      c-- 
      displayFiles(); 
      download(); 
     } 

     document.getElementById('next').onclick = function() { 
      if (c == links.length - 1) { 
       c = -1; 
      } 
      c++; 
      displayFiles(); 
      download(); 
     } 

     document.getElementById('rand').onclick = function() { 
      temp = c; 
      while (c == temp) { 
       c = Math.floor(Math.random() * links.length); 
      } 
      displayFiles(); 
      download(); 
     } 
    } 

    function displayFiles() { 

     test = links[c].substring(links[c].lastIndexOf('.') + 1, links[c].length); 
     document.getElementById('title').innerHTML = displaytext[c]; 

     flashmovie.innerHTML = 
      '<object type="application/x-shockwave-flash" data="' + links[c] + '">' + 
      '<param name="movie" value="' + links[c] + '">' + 
      '<\/object>'; 
    } 

    function download() { 

      document.getElementById('downLink').setAttribute('href', links[c]); 
     } 


    window.addEventListener ? 
     window.addEventListener('load', init, false) : 
     window.attachEvent('onload', init); 
});` 

希望

+1

かかわら知ってはいけません何らかの理由で全画面が表示される – cosmichero2025

+1

Nvm hrefタグにダウンロード属性を含めるのを忘れて、変更するのを忘れてしまいました。正しいjavascriptを投稿します。 – cosmichero2025

+0

htmlタグを追加すると同じ問題が発生しますその名前でダウンロードできる –

関連する問題