How to achieve mobile copy and paste and compatibility?

//html
<input id="inviteLink1" type="text" value="http:www.66ddcc.cn/user/invite?uid=15467789331"/>
<button class="inviteBtn1" data-clipboard-action="copy" data-clipboard-target="-sharpinviteLink1"></button>

//js
$(".inviteBtn1").on("tap", function() {
    try {
        if(window.clipboardData.setData("Text", $("-sharpinviteLink1").val())){
            alert("1");
        }else{
            alert(""" 1");
        }
    } catch(e1) {
        try {
            var clipboard = new Clipboard("-sharpinviteBtn1");
            clipboard.on("success", function(e) {
                e.clearSelection();
                alert("!2")
            });
            clipboard.on("error", function(e) {
                alert(""" 2");
            });
        } catch(e2) {
            inviteLink1.select();
            document.execCommand("copy");
        }
    }
});

as far as I know, there are these three methods. The other methods are not clear. The first method seems to be not compatible. The second plug-in always tells me that Clipboard is not define, is always undefined. I don"t know. The third method doesn"t have much problem trying several browsers under Android, but it doesn"t work under ios.

is there a copy-and-paste feature that is compatible with Android and ios, or what should I do with the second method?
if you do not copy directly to the pasteboard, how to open the copy menu that comes with the browser, automatically check it and let the user click copy.


use the relevant plug-ins to implement easily and quickly, if there is a method that cannot be implemented to search for other plug-ins or platform does not support


I don't know why the previous version of clipboard returned an error in the new instance, but a different version is fine later.

this plug-in can solve the copying of most browsers. This thing may not be complete in the first place, but it may still be left to users to copy manually /

.
Menu