当前位置:网站首页>038 network security JS
038 network security JS
2022-07-01 07:42:00 【Prison plan progress 50%】
List of articles
One : note
JS
JavaScript:
Can be static html Pages achieve dynamic effects ,
Explanatory language ,
Every time the page is refreshed JS Code
From top to bottom
When we visit directly JS Script time , Return plain text content
The running environment is a browser , All security issues that arise , All due to “ Front end security ”
Quick start
JS And HTML zlc
Can appear anywhere
Simple sentences :
Output statement
alert(); # Popup
console.log(); # Output at console
How to be in html Introduction in JS Code
Inside JS
<script>
this is JS code
</script>
external JS
<script src="./js/test.js"></script>
Variable
Declare variables
var name
Variable type
Number
character string
Boolean type
null and undefined
js Our designers want to use null Represents a null value , and undefined Indicates that the value is undefined .
Array :
The array can contain any type
var arry = [1,2,3.14,'hello',null,true]
Array access :arry[2] obtain 3.14
object
Is a set of keys 、 An unordered set of values
var person = {
name:'bob',
age:20,
tags:['js','web','mobile'],
city:'Beijing',
hasCar:true,
zipcode:null
};
Access to object properties :person.name
conditional
var age = 15;
if (age >=18){
alert('adult');
}else{
alert('teenager');
}
for loop
var x=0;
var i;
for(i=1; i<=100; i++){
x= x+ i;
}
x; // 5050
for ... in
for A variant of the cycle , You can loop all the attributes of an object in turn
var x = {
name:'jack',
age:20,
city:'beijing'
};
for(var key in x){
console.log(key); // 'jack','20','city'
}
while loop
var x = 0;
var y = 99;
while(y>0){
x = x+y;
y = y-2;
};
x; // 2500
do while loop
var n = 0;
do{
n=n+1;
}while (n<100);
n; // 100
function :
The advantage of defining a function is that it is easy to call
The function is defined as follows :
function abs(x){
if (x >= 0){
return x;
}else{
return -x;
}
}
abs(x);
Above abs() Function :
function It is pointed out that this is a function definition
abs Is the name of the function
(x) The parameters of the function are listed in parentheses , Multiple parameters with , Separate
( ... ) The code between is the function body , Can contain several statements
object
Operate the browser through objects
window
That is, it acts as a global scope , Also represents the browser window
navigator
Represents the information of the browser , The most common attributes are :
navigator.appName Browser name
navigator.appVersion Browser version
navigator.language Language for browser settings
navigator.platform Type of operating system
navigator.userAgent Browser set User-Agent character string
screen
Information representing the screen , Common properties :
screen.width Screen broadband , In pixels
screen.height Screen height
screen.colorDepth Returns the number of color digits , Such as :8 16 24
location
Represents the... Of the current page URL Information
location.port; // 8080
location.pathname; // '/path/index.html'
location.search; // '?a=1&b=2'
location.hash; // 'TOP'
DOM: Document object model
The first method :
document ** It's very important **
Represents the current page , because html In the browser DOM In the form of tree structure ,document The object is the whole DOM Root node of tree
var test = document.getElementById('test'); // return ID by 'test' The node of
var trs = document.getElementById('test-table').getElementsByTagName('tr'); // First position ID by 'test-table' The node of , And then return to its internal all tr node
var reds = document.getElementById('test-div').getElementsByClassName('red'); // First position ID by 'test-div' The node of , And then return to its internal all class contain red The node of
var cs = test.children; // Access to the node test All direct child nodes under
var first = test.firstElementChild // Access to the node test The first child node under
var last = test.lastElementChild // Access to the node test The last child node under
The second method :
querySelector() and querySelectorAll() Lower version not supported
var q1 = document.querySelector('#q1'); // adopt querySelector obtain ID by q1 The node of 、
var ps = q1.querySelectorAll('div.highlighted > p'); // adopt querySelectorAll obtain q1 All eligible nodes within a node
document.cookie
Can finish cookie Reading and writing of information
alert(document.cookie);
document.cookie = "name=xxx"
event :
User triggered event
Mouse events
onclick
Keyboard events
form event
Event response
Two : Source code and experiment
2.1: Directory structure


2.2: Source code and content display
test.html
<html>
<head>
<title>JS test</title>
<meta charset = "utf-8">
<script>
// this is JS code
alert("hello world");
</script>
<script src="./js/test.js"></script>
</head>
<body>
<h1>
JS TEST page
</h1>
</body>
</html>
<script src="./js/test1.js"></script>
<script src="http://localhost/JS/js/test1.js"></script>
test.js
alert("this is from test.js");
test1.js
alert("this is from test1.js");

Click OK once :
Click OK again :
Click again on the :
func.html
<meta charset="utf-8">
<h1> JS function </h1>
<script>
function abs(x){
// Calculate the absolute value of a number
if (x >= 0){
alert(x);
}else{
alert(-x);
}
}
abs(-1); // Call function
</script>

mode.html
Access to the node
<!-- HTML structure -->
<div id="test-div">
<div class="c-red">
<p id="test-p">JavaScript</p>
<p>Java</p>
</div>
<div class="c-red c-green">
<p>Python</p>
<p>Ruby</p>
<p>Swift</p>
</div>
<div class="c-green">
<p>Scheme</p>
<p>Haskell</p>
</div>
</div>

onclick.html
<meta charset="utf-8">
<input type="button" onclick="alert(/xss/)" value=" Click on me ">
<input type="button" onmouseover="func()" value=" Move the mouse over ">
<script>
function func(){
alert("xss");
}
</script>


For more click events, please refer to :html Event details
边栏推荐
- Inftnews | from "avalanche" to Baidu "xirang", 16 major events of the meta universe in 30 years
- 2022制冷与空调设备运行操作国家题库模拟考试平台操作
- vscode 根据 ESLint 规范自动格式化代码
- redisson使用全解——redisson官方文档+注释(中篇)
- Redisson watchdog mechanism, redisson watchdog performance problems, redisson source code analysis
- 2022电工(中级)复训题库及答案
- [target detection] yolov5, the shoulder of target detection (detailed principle + Training Guide)
- 浅谈CVPR2022的几个研究热点
- Which securities company is better or safer for mobile phone account opening
- [chapter 72 of the flutter problem series] a solution to the problem that pictures taken in the flutter using the camera plug-in are stretched
猜你喜欢

Ctfhub port scan (SSRF)
![[MySQL learning notes 25] SQL statement optimization](/img/01/cf0556961670bb43512caab8d5f4e5.png)
[MySQL learning notes 25] SQL statement optimization

如何制作专属的VS Code主题

2022 tea master (intermediate) recurrent training question bank and answers

Eigen matrix operation Library

Microsoft announces open source (Godel) language model chat robot

Inftnews | from "avalanche" to Baidu "xirang", 16 major events of the meta universe in 30 years

Redisson uses the full solution - redisson official document + comments (Part 2)

base64

2022 Guangdong Provincial Safety Officer a certificate third batch (main person in charge) special operation certificate examination question bank simulated examination platform operation
随机推荐
2022 tea master (intermediate) recurrent training question bank and answers
運維管理系統,人性化操作體驗
Image style migration cyclegan principle
Is it reliable to open an account on the compass with your mobile phone? Is there any potential safety hazard
[MySQL learning notes 26] view
1286_ Implementation analysis of task priority setting in FreeRTOS
2022 Guangdong Provincial Safety Officer a certificate third batch (main person in charge) special operation certificate examination question bank simulated examination platform operation
继妹变继母,儿子与自己断绝关系,世界首富马斯克,为何这么惨?
力扣——求一组字符中的第一个回文字符
Stepsister becomes stepmother, son breaks off relationship with himself, and musk, the world's richest man, why is it so miserable?
【技能】创建.bat快速打开网页
2022年茶艺师(中级)复训题库及答案
在券商账户上买基金安全吗
[MySQL learning notes 25] SQL statement optimization
Minecraft 1.16.5模组开发(五十一) 方块实体 (Tile Entity)
[Shenzhen IO] precise Food Scale (some understanding of assembly language)
Conscience Amway universal wheel SolidWorks model material website
Apple account password auto fill
[software] phantomjs screenshot
weback5基础配置详解