Js应用整理
由于最近项目需要,故对Js代码作出整理:
1. 怎样自动检测用户有没有安装realplayer的插件,并能自动安装它?
在这里,你可以设置x、y的值来设定所固定层的位置,改变setTimeout("MoveLayer('AdLayer');", 20)中20的值为你希望调用MoveLayer()的时间间隔。还有要注意的是,使用的图片最好为透明背景的gif图,以使图片的背景颜色不至于遮住后面的的内容。
3.javascript树的Demo 源代码
文件结构如下
DemoTree
|------MyTree.js
|------tree,html
|------image(存放用到的相关图片)
MyTree.js 内容如下
--------------------------------------------------
var Icon = {
folderOpen: "folderOpen.gif",
folderClose: "folderClose.gif",
fileimage: "file.gif",
plus: "plus.gif",
minus: "minus.gif",
blank: "blank.gif"
}
//set the directory of the pictures
setImagePath = function(sPath) {
for(o in Icon){
tmp = sPath + Icon[o];
Icon[o] = new Image();
Icon[o].src = tmp;
}
}
window.Tree = [];
function MyTree(){
this.id = window.Tree.length;
window.Tree[this.id] = this;
this.target = "_self";
this.nodes = {0:{id:0, superID: -1, Text: null, nodeType: null, childrenNodes: new Array()}};
}
var tr = MyTree.prototype; // create a instence of the MyTree
tr.add = function(key, superid, text, nodetype){
this.nodes[key] = {id: key, superID:superid, Text: text, nodeType: nodetype, childrenNodes: new Array()};
var ch = this.getNode(superid).childrenNodes;
ch[ch.length] = this.nodes[key];
}
// get a certain node by id
tr.getNode = function(key){
if (typeof this.nodes[key] != "undefined")
{
return this.nodes[key];
}
return null;
}
//get a node's parent
tr.getParent = function(key){
if(this.getNode(key) != null){
var skey = this.getNode(key).superID;
if(typeof this.nodes[skey] != "undefined"){
return this.getNode(skey);
} else {
return null;
}
}else{
return null;
}
}
//the status of the children
tr.hasChildren = function(key){
return this.getNode(key).childrenNodes.length > 0
}
//get root
tr.getRoot = function(key) {
if(key == 0)
return this.getNode(key);
var par = this.getParent(key);
if (this.getNode(key).id == 0)
{
return this.getNode(key);
}
else
{
return this.getRoot(par.id);
}
}
//draw a node
tr.drawNode = function(key){
var html = "";
var node = this.getNode(key);
var rootID = this.getRoot(key);
var hc = this.hasChildren(key);
//html += '
if(hc){
var io = key == rootID.id;
html += ('
html += this.drawChild(key);
html += '
}
return html;
}
//draw indent
tr.drawIndent = function(key){
var s = ''
var ir = this.getRoot(key).id == key;
var node = this.getNode(key);
var hc = this.hasChildren(key);
if(this.getParent(key) != null)
s = hc ? '' : '
';
var p = this.getParent(key);
while(p != null)
{
if(this.getParent(p.id) == null)break;
s = ('')+s;
p = this.getParent(p.id);
}
return s;
}
//draw a node's children nodes
tr.drawChild = function(key){
var node = this.getNode(key);
var html = "";
for(var i = 0; i < node.childrenNodes.length; i++){
html += this.drawNode(node.childrenNodes[i].id);
}
return html;
}
//
tr.openHandler = function(key){
var handler = document.getElementById("handler"+key);
var container = document.getElementById("container"+key);
var fimage = document.getElementById("image"+key);
if(container.style.display ==''){
container.style.display = 'none';
handler.src = Icon.plus.src;
fimage.src = Icon.folderClose.src;
}else{
container.style.display = '';
handler.src = Icon.minus.src;
fimage.src = Icon.folderOpen.src;
}
}
//
tr.openFolder = function(key){
}
tr.toString = function(key){
return this.drawChild(0);
}
-----------------------------------------
tree.html代码如下
-----------------------------------------
4.页面漂浮广告
<script>
document.write('<DIV id=mov6 style="POSITION: absolute; width: 10px; height: 10px"><OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" WIDTH=80 HEIGHT=80><PARAM NAME=movie VALUE="http://www.163.net/ad/adv/netcn/netcn_100x100.swf"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="http://www.163.net/ad/adv/netcn/netcn_100x100.swf" quality=high bgcolor=#FFFFFF WIDTH=80 HEIGHT=80 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED></OBJECT><img src="http://bjad.163.net/image.ng/site=www163net&channel=163mainpage&SpaceDesc=mainpage&location=moving2" width="1" height="1" border="0"></DIV>');
var xPos = 250;
var yPos = document.body.clientHeight;
var step = 1;
var delay = 20;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
mov6.style.top = yPos;
function changePos() {
width = document.body.clientWidth;
height = document.body.clientHeight;
Hoffset = mov6.offsetHeight;
Woffset = mov6.offsetWidth;
mov6.style.left = xPos + document.body.scrollLeft;
mov6.style.top = yPos + document.body.scrollTop;
if (yon) {
yPos = yPos + step;
}
else {
yPos = yPos - step;
}
if (yPos < 0) {
yon = 1;
yPos = 0;
}
if (yPos >= (height - Hoffset)) {
yon = 0;
yPos = (height - Hoffset);
}
if (xon) {
xPos = xPos + step;
}
else {
xPos = xPos - step;
}
if (xPos < 0) {
xon = 1;
xPos = 0;
}
if (xPos >= (width - Woffset)) {
xon = 0;
xPos = (width - Woffset);
}
}
function start() {
mov6.visibility = "visible";
interval = setInterval('changePos()', delay);
}
start();
</script>