上代码:

    1. export const isPc = () => {
    2. const ua = navigator.userAgent
    3. const moveDevices = [
    4. "Android",
    5. "iPhone",
    6. "SymbianOS",
    7. "Windows Phone",
    8. "iPad",
    9. "iPod"
    10. ]
    11. let flag = true;
    12. for (let i = 0; i < moveDevices.length; i++) {
    13. if (ua.indexOf(moveDevices[i]) !== -1) {
    14. flag = false;
    15. break
    16. }
    17. }
    18. return flag
    19. }
    20. export const closeCurWebPage = () => {
    21. if (!isPc()) {
    22. window.opener = null
    23. window.open("about:blank", "_self", "").close()
    24. }
    25. if (navigator.userAgent.indexOf(Firefox) !== -1 || navigator.userAgent.indexOf("Chrome") !== -1) {
    26. // 浏览器键入url方式打开的网页
    27. window.location.href = "about:blank"
    28. window.close()
    29. } else {
    30. // 脚本打开的网页
    31. window.opener = null
    32. window.open("about:blank", "_self", "")
    33. window.close()
    34. }
    35. }