- 执行浏览器复制命令
注:只能复制文本框内的文字( input / textarea )
function jsCopy(){
var e = document.getElementById("content");//对象是content
e.select(); //选择对象
document.execCommand("Copy"); //执行浏览器复制命令
alert("已复制好,可贴粘。");
}
- 文件上传进度条 - 原生ajax & 跨域问题
- 用JavaScript将canvas保存成图片格式
// Converts canvas to an image
function convertCanvasToImage(canvas) {
var image = new Image();
image.src = canvas.toDataURL("image/png");
return image;
}
- 低级浏览器升级提示
<!--IE7以下极低级浏览器升级提示--> <!--[if lte IE 7]> <script>window.location.href='http://cdn.dmeng.net/upgrade-your-browser.html?referrer='+location.href;</script> <![endif]-->
- 判断浏览器类型
// 判断浏览器类型
function getBrowser() {
let ua = window.navigator.userAgent;
let isIE = window.ActiveXObject != undefined && ua.indexOf("MSIE") != -1;
let isEdge = ua.indexOf("Trident") != -1;
let isFirefox = ua.indexOf("Firefox") != -1;
let isOpera = window.opr != undefined;
let isChrome = ua.indexOf("Chrome") && window.chrome;
let isSafari = ua.indexOf("Safari") != -1 && ua.indexOf("Version") != -1;
if (isIE) {
return "IE";
} else if (isFirefox) {
return "Firefox";
} else if (isOpera) {
return "Opera";
} else if (isChrome) {
return "Chrome";
} else if (isSafari) {
return "Safari";
} else if (isEdge) {
return "isEdge";
} else {
return "Unkown";
}
}
//判断是移动端还是PC
function isMobileOrPC(){
if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
return 'mobile';
}
return 'pc';
}
export default {
methods : {
getBrowser,
isMobileOrPC
}
}
- 禁止、恢复H5页面滑动
//禁止H5页面滑动
document.body.style.overflow = 'hidden';
function _preventDefault(e) {
e.preventDefault();
}
window.addEventListener('touchmove', _preventDefault);
//恢复滑动
document.body.style.overflow = 'auto';
window.removeEventListener('touchmove', _preventDefault);