ios Safari browser does not support js copy string
Originally designed as: Click the "Copy" button to copy the order number to the clipboard.
It can be found that it does not work in the ios safari browser.
Later found at http://stackoverflow.com/
Reference: http://stackoverflow.com/questions/34045777/copy-to-clipboard-using-javascript-in-ios
Solution:
Determine the operating system type, if it is ios, the "copy" button will not be displayed (because it is displayed, it is useless)
(1) Determine the operating system type
ClientOsInfo info =SpringMVCUtil.getMobileOsInfo(request); model.addAttribute("ostype",info.getOsType());
The value of osType is "Ios", "Android", "WINDOWS PHONE"
public static final String OSTYPE_ANDROID="Android"; public static final String OSTYPE_IOS="Ios"; public static final String OSTYPE_WP="WINDOWS PHONE"; /*** * blackberries */ public static final String OSTYPE_BLACKBERRY="BLACKBERRY";
(2) The front end judges by freeMark :
<#if !(ostype??)|| ostype!='Ios'> <div id="copy_order" >复制</div> <div id="copy_money" >复制</div> </#if>
SpringMVCUtil.getMobileOsInfo
The method is implemented as follows
/** * Determine the operating system of the mobile phone IOS/android/windows phone/BlackBerry * * @param UA * @return */ public static ClientOsInfo getMobilOS(String UA) { if (UA == null) { return null; } UA = UA.toUpperCase (); ClientOsInfo osInfo=new ClientOsInfo(); // store the regular expression String rex = ""; // IOS judgment string String iosString = " LIKE MAC OS X"; if (UA.indexOf(iosString) != -1) { if (StringUtil.isFind(UA, "\\([\\s]*iPhone[\\s]*;", Pattern.CASE_INSENSITIVE)) { osInfo.setDeviceType(DEVICE_TYPE_PHONE); } else if (StringUtil.isFind(UA, "\\([\\s]*iPad[\\s]*;", Pattern.CASE_INSENSITIVE)) { osInfo.setDeviceType(DEVICE_TYPE_PAD); } rex = ".*" + "[\\s]+(\\d[_\\d]*)" + iosString; Pattern p = Pattern.compile(rex, Pattern.CASE_INSENSITIVE); Matcher m = p.matcher (UA); boolean rs = m.find(); if (rs) { String osVersion= m.group(1).replace("_", "."); osInfo.setVersion(osVersion); // System.out.println("Mobil OS is" + " IOS" +osVersion); osInfo.setOsTypeVersion(OSTYPE_IOS+"_" + osVersion); }else{ System.out.println("IOS"); osInfo.setOsTypeVersion(OSTYPE_IOS); } osInfo.setOsType(OSTYPE_IOS); return osInfo; } // Android judgment String androidString = "ANDROID"; if (UA.indexOf(androidString) != -1) { if (StringUtil.isFind(UA, "\\bMobi", Pattern.CASE_INSENSITIVE)) { osInfo.setDeviceType(DEVICE_TYPE_PHONE); }else { osInfo.setDeviceType(DEVICE_TYPE_PAD); } rex = ".*" + androidString + "[\\s]*(\\d*[\\._\\d]*)"; Pattern p = Pattern.compile(rex, Pattern.CASE_INSENSITIVE); Matcher m = p.matcher (UA); boolean rs = m.find(); if (rs) { String version=m.group(1).replace("_", "."); osInfo.setVersion(version); System.out.println("Mobil OS is " + OSTYPE_ANDROID + version); osInfo.setOsTypeVersion(OSTYPE_ANDROID+"_" + version); }else{ System.out.println("Android"); osInfo.setOsTypeVersion(OSTYPE_ANDROID); } osInfo.setOsType(OSTYPE_ANDROID); return osInfo; } // windows phone judgment String wpString = "WINDOWS PHONE"; if (osTypeMatch(UA, osInfo, wpString)) return osInfo; // BlackBerry BlackBerry system judgment String bbString = "BLACKBERRY"; if (UA.indexOf(bbString) != -1) { rex = ".*" + bbString + "[\\s]*([\\d]*)"; Pattern p = Pattern.compile(rex, Pattern.CASE_INSENSITIVE); Matcher m = p.matcher (UA); boolean rs = m.find(); if (rs) { System.out.println("Mobil OS is" + " BLACKBERRY " + m.group(1)); String version=m.group(1); osInfo.setVersion(version); osInfo.setOsTypeVersion(OSTYPE_BLACKBERRY+"_" + version); }else{ System.out.println("BLACKBERRY"); osInfo.setOsTypeVersion(OSTYPE_BLACKBERRY); } osInfo.setOsType(OSTYPE_BLACKBERRY); return osInfo; } if(UA.contains("LINUX")){//android if (StringUtil.isFind(UA, "\\bMobi", Pattern.CASE_INSENSITIVE)) { osInfo.setDeviceType(DEVICE_TYPE_PHONE); }else { osInfo.setDeviceType(DEVICE_TYPE_PAD); } Pattern p = Pattern.compile("U;\\s*(Adr[\\s]*)?(\\d[\\.\\d]*\\d)[\\s]*;",Pattern.CASE_INSENSITIVE); Matcher m = p.matcher (UA); boolean result = m.find(); String find_result = null; if (result) { find_result = m.group(2); } if(StringUtil.isNullOrEmpty(find_result)){ osInfo.setOsTypeVersion(OSTYPE_ANDROID); return osInfo; }else{ osInfo.setVersion(find_result); osInfo.setOsTypeVersion(OSTYPE_ANDROID+"_"+find_result); return osInfo; } } //UCWEB/2.0 (iOS; U; iPh OS 4_3_2; zh-CN; iPh4) if(UA.matches(".*((IOS)|(iPAD)).*(IPH).*")){ if (StringUtil.isFind(UA, "[\\s]*iPh[\\s]*", Pattern.CASE_INSENSITIVE)) { osInfo.setDeviceType(DEVICE_TYPE_PHONE); }else { osInfo.setDeviceType(DEVICE_TYPE_PAD); } Pattern p = Pattern.compile("U;\\s*(IPH[\\s]*)?(OS[\\s]*)?(\\d[\\._\\d]*\\d)[\\s]*;",Pattern.CASE_INSENSITIVE); Matcher m = p.matcher (UA); boolean result = m.find(); String find_result = null; if (result) { find_result = m.group(3); } if(StringUtil.isNullOrEmpty(find_result)){ osInfo.setOsTypeVersion(OSTYPE_IOS); osInfo.setOsType(OSTYPE_IOS); return osInfo; }else{ String version=find_result.replace("_", "."); osInfo.setVersion(version); osInfo.setOsTypeVersion(OSTYPE_IOS+"_"+version); osInfo.setOsType(OSTYPE_IOS); return osInfo; } } return osInfo; } /*** * Get the operating system information of the mobile terminal when the mobile terminal (mobile phone or Pad) accesses the webpage * @param request * @return */ public static ClientOsInfo getMobileOsInfo(HttpServletRequest request){ String userAgent=request.getHeader("user-agent"); if(StringUtil.isNullOrEmpty(userAgent)){ userAgent=request.getHeader("User-Agent"); } ClientOsInfo info= getMobilOS(userAgent); if (null == info) {//In order to pass the unit test info = new ClientOsInfo(); } info.setUserAgent(userAgent); return info; }