如何使用 js 检测页面上全局变量

js 检测页面全局变量脚本

<!DOCTYPE html>
<html lang="zh-Hans">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="author" content="xgqfrms">
<meta name="generator" content="VS code">
<title>window-global-var-checker</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
</style>
<link rel="stylesheet" href="./index.css">
</head>
<body>
<header>
<h1>window-global-var-checker</h1>
</header>
<main>
<article>
<section>
<a href="https://feiqa.xgqfrms.xyz/index.html"></a>
</section>
</article>
</main>
<footer>
<p>copyright&copy; xgqfrms 2020</p>
</footer>
<!-- js -->
<script>
const log = console.log;
const vars = Object.keys(window);
log(`window global vars =`, vars, vars.length);
try {
if(window.copy) {
window.copy(vars);
}
} catch (error) {
log(`copy error`, error);
}
</script>
</body>
</html>

Map / Set

去重

"use strict";

/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-10-01
* @modified
*
* @description
* @difficulty Easy Medium Hard
* @complexity O(n)
* @augments
* @example
* @link https://www.cnblogs.com/xgqfrms/p/13794239.html
* @solutions
*
* @best_solutions
*
*/ const log = console.log; // empty page keys
const window_global_vars = [...Object.keys(window)]; const autoFindAllGlobalVars = (vars = Object.keys(window)) => {
const result = [];
const arr = [...new Set(vars)];
// log(`arr =`, arr);
for(const item of arr) {
if(!window_global_vars.includes(item)) {
log(`item =`, item);
result.push(item);
} else {
// do nothing
}
}
return result;
} // autoFindAllGlobalVars(); const window = ["jquery", "react", "vue", "angular", "node.js", ...window_global_vars];
// log(`window =`, window); const test = autoFindAllGlobalVars(window);
log(`\ntest =`, test);

window global vars

Chrome

const window_global_vars = [
"window",
"self",
"document",
"name",
"location",
"customElements",
"history",
"locationbar",
"menubar",
"personalbar",
"scrollbars",
"statusbar",
"toolbar",
"status",
"closed",
"frames",
"length",
"top",
"opener",
"parent",
"frameElement",
"navigator",
"origin",
"external",
"screen",
"innerWidth",
"innerHeight",
"scrollX",
"pageXOffset",
"scrollY",
"pageYOffset",
"visualViewport",
"screenX",
"screenY",
"outerWidth",
"outerHeight",
"devicePixelRatio",
"clientInformation",
"screenLeft",
"screenTop",
"defaultStatus",
"defaultstatus",
"styleMedia",
"onsearch",
"isSecureContext",
"performance",
"onappinstalled",
"onbeforeinstallprompt",
"crypto",
"indexedDB",
"webkitStorageInfo",
"sessionStorage",
"localStorage",
"onabort",
"onblur",
"oncancel",
"oncanplay",
"oncanplaythrough",
"onchange",
"onclick",
"onclose",
"oncontextmenu",
"oncuechange",
"ondblclick",
"ondrag",
"ondragend",
"ondragenter",
"ondragleave",
"ondragover",
"ondragstart",
"ondrop",
"ondurationchange",
"onemptied",
"onended",
"onerror",
"onfocus",
"onformdata",
"oninput",
"oninvalid",
"onkeydown",
"onkeypress",
"onkeyup",
"onload",
"onloadeddata",
"onloadedmetadata",
"onloadstart",
"onmousedown",
"onmouseenter",
"onmouseleave",
"onmousemove",
"onmouseout",
"onmouseover",
"onmouseup",
"onmousewheel",
"onpause",
"onplay",
"onplaying",
"onprogress",
"onratechange",
"onreset",
"onresize",
"onscroll",
"onseeked",
"onseeking",
"onselect",
"onstalled",
"onsubmit",
"onsuspend",
"ontimeupdate",
"ontoggle",
"onvolumechange",
"onwaiting",
"onwebkitanimationend",
"onwebkitanimationiteration",
"onwebkitanimationstart",
"onwebkittransitionend",
"onwheel",
"onauxclick",
"ongotpointercapture",
"onlostpointercapture",
"onpointerdown",
"onpointermove",
"onpointerup",
"onpointercancel",
"onpointerover",
"onpointerout",
"onpointerenter",
"onpointerleave",
"onselectstart",
"onselectionchange",
"onanimationend",
"onanimationiteration",
"onanimationstart",
"ontransitionrun",
"ontransitionstart",
"ontransitionend",
"ontransitioncancel",
"onafterprint",
"onbeforeprint",
"onbeforeunload",
"onhashchange",
"onlanguagechange",
"onmessage",
"onmessageerror",
"onoffline",
"ononline",
"onpagehide",
"onpageshow",
"onpopstate",
"onrejectionhandled",
"onstorage",
"onunhandledrejection",
"onunload",
"alert",
"atob",
"blur",
"btoa",
"cancelAnimationFrame",
"cancelIdleCallback",
"captureEvents",
"clearInterval",
"clearTimeout",
"close",
"confirm",
"createImageBitmap",
"fetch",
"find",
"focus",
"getComputedStyle",
"getSelection",
"matchMedia",
"moveBy",
"moveTo",
"open",
"postMessage",
"print",
"prompt",
"queueMicrotask",
"releaseEvents",
"requestAnimationFrame",
"requestIdleCallback",
"resizeBy",
"resizeTo",
"scroll",
"scrollBy",
"scrollTo",
"setInterval",
"setTimeout",
"stop",
"webkitCancelAnimationFrame",
"webkitRequestAnimationFrame",
"chrome",
"caches",
"ondevicemotion",
"ondeviceorientation",
"ondeviceorientationabsolute",
"cookieStore",
"showDirectoryPicker",
"showOpenFilePicker",
"showSaveFilePicker",
"speechSynthesis",
"onpointerrawupdate",
"trustedTypes",
"openDatabase",
"webkitRequestFileSystem",
"webkitResolveLocalFileSystemURL"
];

refs



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


如何使用 js 检测页面上全局变量的更多相关文章

  1. js检测页面上一个元素是否已经滚动到了屏幕的可视区域内

    应用场景:只要页面加载了,其中在页面中出现的li就向控制台输出第几个发送请求:在本次加载的页面中,再将滚动条滚回前边的li,不再向控制台输出东西,也就是说已经显示过的li,不再向控制台输出东西. &l ...

  2. Progress.js – 为页面上的任意对象创建进度条效果

    Progress.js 是一个 JavaScript 和 CSS3 的库,它帮助开发人员为网页上的每个对象创建和管理进度条效果.你可以设计自己的模板,进度条或者干脆定制. 您可以使用 Progress ...

  3. JS 在页面上直接将json数据导出到excel,支持chrome,edge,IE10+,IE9,IE8,Safari,Firefox

    JS 在页面上直接将json数据导出到excel,支持chrome,edge,IE10+,IE9,IE8,Safari,Firefox <html> <head> </h ...

  4. 使用js在页面上新建文件夹

    使用js在页面上新建文件夹 <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...

  5. js禁用页面上右键菜单、选中和复制

    有时候我们不想页面上的内容被人复制走,那么就可以使用js对页面进行设置,禁止右键菜单.禁止选中.禁止复制等功能可以有效的达到这个效果,js代码如下所示: /** * 禁用右键菜单 */ documen ...

  6. js检查页面上有无重复id的代码分享

    用js代码检查一个页面上是否用重复的id. 方法一: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ...

  7. 如何用JS获取页面上的所有标签

    最近忙的一匹,忙着大保健,都来不及写博客,今天特意抽出点时间来写一写 前两天看到一个题,是问如何从页面上获取所有的标签的并查看他们的数量,感觉还是有点意思的,所以给大家来搞一下子 我们先来捋捋思路,那 ...

  8. 用JS检测页面加载的不同阶段状态

    这可以通过用document.onreadystatechange的方法来监听状态改变, 然后用document.readyState == “complete”判断是否加载完成. 可以采用2个div ...

  9. JS 将页面上的表格导出为 Excel 文件

    如果在页面上展示了一个表格,想把这个表格导出为Excel文件,那么在要求不高的情况下,可以直接利用 JavaScript 的 Blob 和 Object URL 特性将表格导出.不过,这就是利用了 E ...

随机推荐

  1. LoadRunner监控Centos和Ubuntu资源之服务器配置

    Centos 我用的版本是Centos6.8   首先更新源以及基础操作我就不说了,直接上步骤: Step 1 安装相关程序 执行命令:yum install inetd,这一步是为了安装rstatd ...

  2. Mysql数据库下InnoDB数据引擎下的事务详解

    一.什么是数据库事务? 数据库事务( transaction)是访问并可能操作各种数据项的一个数据库操作序列,这些操作要么全部执行,要么全部不执行,是一个不可分割的工作单位.事务由事务开始与事务结束之 ...

  3. NIO非阻塞网络编程原理

    NIO非阻塞网络编程原理 1.NIO基本介绍 Java NIO 全称 java non-blocking IO,是指 JDK 提供的新 API.从 JDK1.4 开始,Java 提供了一系列改进的 输 ...

  4. node集群(cluster)

    使用例子 为了让node应用能够在多核服务器中提高性能,node提供cluster API,用于创建多个工作进程,然后由这些工作进程并行处理请求. // master.js const cluster ...

  5. Shell 简单入门教程

    大数据开发岗为什么要学习Shell呢?1)需要看懂大数据运维岗人员编写的Shell程序.2)偶尔会编写一些简单Shell程序来管理集群.提高开发效率 艺多不压身 Shell是一个命令行解释器,它接受应 ...

  6. Webpack4.0各个击破(6)loader篇

    目录 一. loader综述 二. 如何写一个loader 三. loader的编译器本质 [参考] 一. loader综述 loader是webpack的核心概念之一,它的基本工作流是将一个文件以字 ...

  7. mysql中int型的数字怎么转换成字符串

    字段:number  是integer类型    在表test中 select cast(number as char) as number from test; 或者convert()方法.因为转换 ...

  8. vim 行号的显示与隐藏

    通常我们在使用vim编辑器的时候,需要显示和隐藏行号 隐藏行号: 1.首先我们vim   1.txt   (进入我们编辑的文档),如下,此时是显示行号的 2.按一下esc键,并输入:(冒号),完成效果 ...

  9. CF570B

    题意转化: 一条长为n的路,路上有一点m,问你在什么地方再设一点a可以使路上任意一点到点a的概率大于到点m的概率 所谓概率更大,也就是说从离点m更远的一端到点a的长度小于到点m的长度 (因为此长度内所 ...

  10. 搭建Spring相关框架后,配置信息文件头部出现红色小×错误。

    问题描述: 在搭建关于Spring相关框架的时候,在applicationContext.xml配置文件和servlet-mvc.xml配件文件的头部会出现一个红色的小X错误: 错误描述: Refer ...