js弹出窗口 + 获取上传文件全路径

1. 自动弹出窗口

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DIVCSS5可拖动DIV提示窗口</title>
<script language="javascript">
function alertWin(title, msg, w, h){
var content = "<br/><br/><input type='file' name='file' id='file' value='浏览'/>";
content += "<br/><p align='left'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>*</font>注意文件格式应为.xls</p>";
content += "<input type='submit' value='提交'/>";
msg = content;
var titleheight = "22px"; // 提示窗口标题高度
var bordercolor = "#666699"; // 提示窗口的边框颜色
var titlecolor = "#FFFFFF"; // 提示窗口的标题颜色
var titlebgcolor = "#666699"; // 提示窗口的标题背景色
var bgcolor = "#FFFFFF"; // 提示内容的背景色

var iWidth = document.documentElement.clientWidth;
var iHeight = document.documentElement.clientHeight;
var bgObj = document.createElement("div");
bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+Math.max(document.body.clientHeight, iHeight)+"px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#000000;z-index:101;";
document.body.appendChild(bgObj);

var msgObj=document.createElement("div");
msgObj.style.cssText = "position:absolute;font:11px '宋体';top:"+(iHeight-h)/2+"px;left:"+(iWidth-w)/2+"px;width:"+w+"px;height:"+h+"px;text-align:center;border:1px solid "+bordercolor+";background-color:"+bgcolor+";padding:1px;line-height:22px;z-index:102;";
document.body.appendChild(msgObj);

var table = document.createElement("table"); //www.divcss5.com divcss5
msgObj.appendChild(table);
table.style.cssText = "margin:0px;border:0px;padding:0px;";
table.cellSpacing = 0;
var tr = table.insertRow(-1);
var titleBar = tr.insertCell(-1);
titleBar.style.cssText = "width:100%;height:"+titleheight+"px;text-align:left;padding:3px;margin:0px;font:bold 13px '宋体';color:"+titlecolor+";border:1px solid " + bordercolor + ";cursor:move;background-color:" + titlebgcolor;
titleBar.style.paddingLeft = "10px";
titleBar.innerHTML = title;
var moveX = 0;
var moveY = 0;
var moveTop = 0;
var moveLeft = 0;
var moveable = false;
var docMouseMoveEvent = document.onmousemove; //www.divcss5.com divcss5
var docMouseUpEvent = document.onmouseup;
titleBar.onmousedown = function() {
var evt = getEvent();
moveable = true;
moveX = evt.clientX;
moveY = evt.clientY;
moveTop = parseInt(msgObj.style.top);
moveLeft = parseInt(msgObj.style.left);

document.onmousemove = function() {
if (moveable) {
var evt = getEvent();
var x = moveLeft + evt.clientX - moveX; //www.divcss5.com divcss5
var y = moveTop + evt.clientY - moveY;
if ( x > 0 &&( x + w < iWidth) && y > 0 && (y + h < iHeight) ) {
msgObj.style.left = x + "px";
msgObj.style.top = y + "px";
}
}
};
document.onmouseup = function () {
if (moveable) {
document.onmousemove = docMouseMoveEvent; //www.divcss5.com divcss5
document.onmouseup = docMouseUpEvent;
moveable = false;
moveX = 0;
moveY = 0;
moveTop = 0;
moveLeft = 0;
}
};

}

var closeBtn = tr.insertCell(-1);
closeBtn.style.cssText = "cursor:pointer; padding:2px;background-color:" + titlebgcolor;
closeBtn.innerHTML = "<span style='font-size:15pt; color:"+titlecolor+";'>×</span>";
//关闭窗口
closeBtn.onclick = function(){
document.body.removeChild(bgObj);
document.body.removeChild(msgObj);
}
var msgBox = table.insertRow(-1).insertCell(-1);
msgBox.style.cssText = "font:10pt '宋体';";
msgBox.colSpan = 2;
msgBox.innerHTML = msg;

// 获得事件Event对象,用于兼容IE和FireFox
function getEvent() {
return window.event || arguments.callee.caller.arguments[0];
}
}
</script>
</head>
<body>
<input type="button" value="DIVCSS5" οnclick="alertWin('批量添加校友信息','内容',300,200);" />
</body>
</html>
 

 2. js获取上传文件全路径

<html>  
<head>  
    <title>Untitled Page</title>  
<script language="javascript">
function readFile(fileBrowser) {  
    if (navigator.userAgent.indexOf("MSIE")!=-1)  //浏览器为IE
        readFileIE(fileBrowser);  
    else if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Mozilla")!=-1)  //浏览器为firefox
        readFileFirefox(fileBrowser);  
    else  
        alert("Not IE or Firefox (userAgent=" + navigator.userAgent + ")");  
}  
  //firefox获取文件全路径的方法
function readFileFirefox(fileBrowser) {  
    try {  
        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
    }   
    catch (e) {  
        alert('Unable to access local files due to browser security settings. To overcome this, follow these steps: (1) Enter "about:config" in the URL field; (2) Right click and select New->Boolean; (3) Enter "signed.applets.codebase_principal_support" (without the quotes) as a new preference name; (4) Click OK and try loading the file again.');  
        return;  
    }  
  
    var fileName=fileBrowser.value;  
    var file = Components.classes["@mozilla.org/file/local;1"]  
        .createInstance(Components.interfaces.nsILocalFile);  
    try {  
        // Back slashes for windows  
        file.initWithPath( fileName.replace(/\//g, "\\\\") );  
    }  
    catch(e) {  
        if (e.result!=Components.results.NS_ERROR_FILE_UNRECOGNIZED_PATH) throw e;  
        alert("File '" + fileName + "' cannot be loaded: relative paths are not allowed. Please provide an absolute path to this file.");  
        return;  
    }  
  
    if ( file.exists() == false ) {  
        alert("File '" + fileName + "' not found.");  
        return;  
    }  
    alert(file.path); // I test to get the local file's path.  
}  
  //IE获取文件全路径方法
function readFileIE(fileBrowser) {  
        var path = fileBrowser.value;
        alert("path is " + path);
  
}
</script>  

  
</head>  
<body>  
    <form name="form1">  
    Browse to select a file  
    <input type="file" name="fileBrowser" size="125" οnchange="readFile(this)" />  
    </form>  
</body>  
</html> 
 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值