2013-06-29 47 views
0

工作我搜索了很多的答案,但我不知道如何解決這個問題?的OnClick無法在Chrome

所以我有一個登陸頁面,我想加一個箭頭這就是地步下載文件(在左邊的按鈕中)。

對於箭頭我用這個代碼:http://jsfiddle.net/hY2Ce/4/

的問題是,其作品在Safari但鉻偉大它不顯示箭頭...

我的代碼:http://jsfiddle.net/zP5Km/

如果你需要更多的代碼只是告訴我...

非常感謝!

的Javascript

navigator.sayswho= (function(){ 
    var N= navigator.appName, ua= navigator.userAgent, tem; 
    var M= ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i); 
    if(M && (tem= ua.match(/version\/([\.\d]+)/i))!= null) M[2]= tem[1]; 
    M= M? [M[1], M[2]]: [N, navigator.appVersion,'-?']; 
    return M; 
})(); 
// http://stackoverflow.com/questions/2400935/browser-detection-in-javascript#2401861 
//console.log(navigator.sayswho); 

function auK(auy) { 
    $(auy).fadeIn(750, function() { 
     setTimeout(function() { 
      $(auy).fadeOut(1000); 
     }, 10000); 
    }); 
} 

function download() { 
    if (navigator.sayswho[0].toLowerCase() == 'chrome') { 
     auK('#arrow-chrome'); 

    } 
    if ((navigator.sayswho[0].toLowerCase() == 'msie') && (navigator.sayswho[1] == 9.0)) { 
     auK('#arrow-ie'); 

    } 
    if (navigator.sayswho[0].toLowerCase() == 'safari' && (navigator.platform.toUpperCase().indexOf('MAC')>=0)) { 
     auK('#arrow-safari-mac'); 

    } 
} 

HTML

<a href="http://www.example.com/test.exe" class="top-download-button" onclick="download()" > 
    <img class="a" src="img/download-button.png" alt="Download"> 
    <img class="b" src="img/download-button-hover.png" alt="Download" > 
</a> 

<div id="arrow-chrome"></div> 
<div id="arrow-ie"></div> 
<div id="arrow-safari-mac"></div> 

CSS

#arrow-chrome, #arrow-ie, #arrow-safari-mac { 
    position: fixed; 
    display: none; 
    z-index: 10; 
    height: 309px; 
    width: 186px; 
} 

#arrow-chrome { 
    bottom: 10px; 
    left: 20px; 
    background: url("http://cdn.mediafire.com/images/backgrounds/download/dlpointers/arrow_down.png") no-repeat scroll center center transparent; 
} 

#arrow-ie { 
    bottom: 10px; 
    left: 50%; 
    margin-left: -140px; 
    background: url("http://cdn.mediafire.com/images/backgrounds/download/dlpointers/arrow_down.png") no-repeat scroll center center transparent; 
} 

#arrow-safari-mac { 
    top: 10px; 
    right: 10px; 
    z-index: 100 !important; 
    background: url("http://cdn.mediafire.com/images/backgrounds/download/dlpointers/arrow_up.png") no-repeat scroll center center transparent; 
} 

html,body { 
    width:100%; 
    height:100%; 
} 
+0

只需粘貼代碼,hilight /選擇它,然後按ctrl + k。無論如何,我感謝你發佈了一個鏈接。在加載時,控制檯會寫入兩個錯誤:GET http://fiddle.jshell.net/_display/img/download-button.png 404(Not Found)fiddle.jshell.net/:89 GET http:// fiddle。 jshell.net/_display/img/download-button-hover.png 404(找不到)fiddle.jshell.net/:89 – user2350838

+0

是的,我不想在這裏上傳所有的代碼...如果你有時間發送郵件到[email protected],我會將所有文件發送給您 – user535351

+0

您是否解決了這個問題?你的jsfiddle適用於我的Chrome – Mataniko

回答

0

試試這個代碼:

<a class="top-download-button" onclick="download(); window.location='test.exe';" > 
<img class="a" src="img/download-button.png" alt="Download"> 
<img class="b" src="img/download-button-hover.png" alt="Download" > 
</a> 
+0

用這段代碼我甚至不能按下按鈕來下載鉻...但它仍然在safari – user535351

+0

工作,那麼我得到了正確的解決方案爲你,添加iframe,保持它隱藏沒有來源,並在onclick,這樣做: onclick =「download(); document.getElementById('iframeId').src ='http://www.example.com/test.exe';「 – saleem

+0

它的工作!我修改此代碼http://jsfiddle.net/at9Jy/3/及其很棒! – user535351