龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > Javascript编程 >

浅谈Javascript函数劫持(1)(3)

时间:2013-03-06 14:58来源:未知 作者:admin 点击:
分享到:
五、附录 [1]简易的javascript inline debugger代码 http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd http://www.w3.org/1999/xhtml style=margin-left: 300px; / /* FileName: js_inline_debugg

五、附录

[1]简易的javascript inline debugger代码


 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">



style="margin-left: 300px;" />

 

/*
FileName:        js_inline_debugger.js
Author:            luoluo
Contact:        luoluonet_at_yahoo.cn
Date:            2007-6-27
Version:        0.1
Usage:   
 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">






Instruction:   
It is a simple javascript inline debugger. You must

add xhtml1-transitional dtd to your
html document if you wanna to use the script.
*/

//--------------------------------------------------------------------------//
// 公用的函数
//--------------------------------------------------------------------------//
// 判断是否是IE
function isIE() {
return document.all && window.external;
}

// 去除字符串两边的空格
String.prototype.trim = function() {
var re = /(^s*)|(s*)$/g;
return this.replace(re, "");
}

// 删除数组中某个元素
Array.prototype.remove = function(i) {
var o = this[i];
for (var j = i; j < this.length - 1; j ++) {
this[j] = this[j + 1];
}
-- this.length;
return o;
}

// 判断一个数组中是否存在相同的元素
Array.prototype.search = function(o) {
for (var i = 0; i < this.length; i ++) {
if (this[i] == o) {
return i;
}
}

return -1;
}

// html编码
function htmlEncode(s) {
s = s.replace(/&/g, "&");
s = s.replace(/s = s.replace(/>/g, ">");
s = s.replace(/"/g, """);
s = s.replace(/'/g, """);

return s;
}

// js编码
function jsEncode(s) {
s = s.replace(//g, "");
s = s.replace(/n/g, "n");
s = s.replace(/"/g, """);
s = s.replace(/'/g, "'");
return s;
}

//--------------------------------------------------------------//
// 命令行窗口工具
//--------------------------------------------------------------//
function Console(parentNode, processInputProc) {
// 窗口
var panel = document.createElement("div");
panel.style.width = "250px";
panel.style.height = "250px";
panel.style.borderColor = "#666666";
panel.style.borderWidth = "1px";
panel.style.backgroundColor = "#ffffff";
panel.style.borderStyle = "solid";
panel.style.position = "absolute";
panel.style.zIndex = 100;
parentNode.appendChild(panel);

// 标题栏
var title = document.createElement("div");
title.style.width = "250px";
title.style.height = "15px";
title.style.backgroundColor = "#dddddd";
title.style.fontSize = "12px";
title.style.fontFamily = "verdana,tahoma";
panel.appendChild(title);

// 标题栏拖动窗口功能
var isDragging = false;
var startPos = new Position(panel.offsetLeft, panel.offsetTop);
var startMousePos = new Position(0, 0);

title.onmouseover = function(evt) {
this.style.cursor = "pointer";
}

title.onmousedown = function(evt) {
if (isDragging == true) {
return;
}

var event = evt || window.event;
startMousePos.x = event.clientX;
startMousePos.y = event.clientY;
isDragging = true;
}

title.onmousemove = function(evt) {
if (isDragging == false) {
return;
}

activateWindow();
var event = evt || window.event;
panel.style.left = (event.clientX - startMousePos.x) + startPos.x + "px";
panel.style.top = (event.clientY - startMousePos.y) + startPos.y + "px";
}

title.onmouseup = function(evt) {
if (isDragging == false) {
return;
}

var event = evt || window.event;
startPos.x =  (event.clientX - startMousePos.x) + startPos.x;
panel.style.left = startPos.x + "px";
startPos.y = (event.clientY - startMousePos.y) + startPos.y;
panel.style.top = startPos.y + "px";
isDragging = false;
}

// 关闭窗口功能
var closeButton = document.createElement("div");
closeButton.style.width = "13px";
closeButton.style.height = "13px";
closeButton.style.backgroundColor = "#ffffff";
closeButton.style.styleFloat = closeButton.style.cssFloat = "left";
closeButton.style.fontSize = "12px";
closeButton.style.borderWidth = "1px";
closeButton.style.borderColor = "#999999";
closeButton.style.borderStyle = "solid";
closeButton.style.paddingButton = "2px";
closeButton.innerHTML = "

x
精彩图集

赞助商链接