Nenhuma Descrição

common.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * given an url with query parameters, this function returns all the
  3. * query parameters as an object with name and value as key and value respectively.
  4. */
  5. function parseQueryString(url) {
  6. var urlObj = {};
  7. var reg = /([^?=&]+)=([^?=&]+)/g;
  8. url.replace(reg, ($0, $1, $2) => {
  9. urlObj[$1] = decodeURIComponent($2);
  10. })
  11. return urlObj;
  12. }
  13. //复制
  14. function goCopy (data) {
  15. // var data = document.getElementById('copy').innerHTML;
  16. copy_2.innerHTML = data;
  17. copy_1.setAttribute('value',data)
  18. if(Boolean(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i))){
  19. //区分iPhone设备
  20. window.getSelection().removeAllRanges();//这段代码必须放在前面否则无效
  21. var Url2=document.getElementById("copy_2");//要复制的节点
  22. var range = document.createRange();
  23. //选中需要复制的节点
  24. range.selectNode(Url2);
  25. //执行选中元素
  26. window.getSelection().addRange(range);
  27. //执行copy操作
  28. var successful = document.execCommand("copy");
  29. //移除选中的元素
  30. window.getSelection().removeAllRanges();
  31. }else{
  32. var Url2=document.getElementById("copy_1");//要复制的节点
  33. Url2.select();//选择对象
  34. document.execCommand("Copy");//执行浏览器复制命令
  35. }
  36. showMsg("复制成功,请到浏览器中打开链接")
  37. }
  38. /**
  39. * [showMsg 提示各种错误信息,3s后消失]
  40. */
  41. function showMsg(msg) {
  42. var msgBox = $('.alert-info');
  43. msgBox.children('p').text(msg);
  44. msgBox.show();
  45. setTimeout(function() {
  46. msgBox.hide();
  47. }, 1500);
  48. }