2017-06-16 48 views
0

我在android webview中創建了一個應用程序,我希望可以複製某些東西。所以當你按下一個按鈕時,你將有東西被複制到你的剪貼板。 我試過"clipboard.js"工作瀏覽器,但不是在Android上。所以我用這個javascript:當你選擇[CSS,JS,android]時,防止標準動作

var copyXBT = function() { 
var theTheCopyXBTAdr = $('#theToCopyXBT'); 
theTheCopyXBTAdr.select(); 
try { 
    var successful = document.execCommand('copy'); 
    var msg = successful ? 'successful' : 'unsuccessful'; 
    console.log('Copying text command was ' + msg); 
} catch (err) { 
    console.log('Oops, unable to copy'); 
} 

};

但是,當你按下輸入類型文本將得到一個藍色,..和藍色邊框(android webview黃色),並在Android上你的鍵盤會彈出。

我用這個CSS樣式來「隱藏」它。因爲我不能說沒有顯示。如果我這樣做,我不會工作。

#theToCopyETH{ 
color: white; 
border: 0px solid white; 
} 

::selection{ 
    background: white; 
    color: white; 
} 

這是我的一塊HTML的:

<button class="btn btn-coinchecker" id="copyETH">Copy ETH address</button><button class="btn btn-coinchecker" data-toggle="modal" data-target="#showETHQR">Click me to get the QR-code</button> 
     <input type="text" id="theToCopyETH" value="*********************"> 

例如參見fiddle。(請在谷歌瀏覽器打開)

所以我的問題是如何防止的彈出鍵盤和android系統中擺脫黃色邊框(谷歌桌面版Chrome是藍色)

預先感謝幫助我!

回答

0

我找到了答案。

什麼我需要做的隱藏我的鍵盤是這個js:

enter var hidekeyboard = function (e) { 
    e.attr('readonly', 'readonly'); // Force keyboard to hide on input field. 
    e.attr('disabled', 'true'); // Force keyboard to hide on textarea field. 
    setTimeout(function() { 
     e.blur(); //actually close the keyboard 
     // Remove readonly attribute after keyboard is hidden. 
     e.removeAttr('readonly'); 
     e.removeAttr('disabled'); 
    }, 100) 
}; 

我需要補充的是我的選擇已happend否則以後我將無法正常工作。 我copyETH看起來是這樣,那麼:

var copyETH = function() { 
var theTheCopyETHAdr = $('#theToCopyETH'); 
theTheCopyETHAdr.removeClass('toggleDisplay'); 
theTheCopyETHAdr.select(); 
try { 
    var successful = document.execCommand('copy'); 
    var msg = successful ? 'successful' : 'unsuccessful'; 
    console.log('Copying text command was ' + msg); 
} catch (err) { 
    console.log('Oops, unable to copy'); 
} 
hidekeyboard(theTheCopyETHAdr); 
theTheCopyETHAdr.addClass('toggleDisplay'); 
}; 

所以你可以看到我也做了removeClass和addClass。因爲如果我只用hidekeyboard可以看到選擇,但與他的CSS類就不見了+,沒有人可以改變輸入字段。

這裏看到解決fiddle

-1

這應該足以隱藏輸入,並防止任何活動時,它的點擊/竊聽,但不會打破你的JS:

#theToCopyETH { 
    visibility: hidden; 
    pointer-events: none; 
} 
+0

visibility:hidden的;行爲與顯示無相同;和指針的事件,什麼也不做,但感謝! – Steven