`

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

    博客分类:
  • UI
 
阅读更多

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" onclick="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" onchange="readFile(this)" />  
    </form>  
</body>  
</html> 
 

 

  • UI.rar (3.8 KB)
  • 下载次数: 128
分享到:
评论
1 楼 tigerwood008 2015-11-10  
IE11不好用!!

相关推荐

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

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

    大名鼎鼎SWFUpload- Flash+JS 上传

     file_dialog_start_handler : file_dialog_start_function, 当文件选取对话框弹出前出发的事件处理函数  file_queued_handler : file_queued_function,  file_queue_error_handler : file_queue_error_function...

    商用版本文本编辑器DotNetTextBoxV6.0.8Source 源码

    1)修正了IE5.5和IE6.0浏览器下上传弹出窗口显示不完全的BUG! 2)修正打开上传窗口时会弹出参数无效的BUG! 3)增加了在IE8浏览器下控件显示不正确的解决办法(更新到faq.htm页面)! 2009/03/23 Version 6.0.2 For VS...

    DotNetTextBox V6.0.10 商业版 下载 (已知最新)

    1)修正了IE5.5和IE6.0浏览器下上传弹出窗口显示不完全的BUG! 2)修正打开上传窗口时会弹出参数无效的BUG! 3)增加了在IE8浏览器下控件显示不正确的解决办法(更新到faq.htm页面)! 2009/03/23 Version 6.0.2 For...

    DotNetTextBox所见即所得编辑器控件 v3.3.1

    2) 改进了自定义插件(弹出窗口)的功能,配置中仅需定义页面名称即可,控件会自动识别系统文件夹位置。 3) 优化部分代码。 4) 增加商业版的演示地址。 &lt;br&gt; 2007/8/15 Version 3.3.0 Free &lt;br&gt;...

    net实用类50个常用方法升级版分页

    ///FileSize()获取上传文件大小 ///FileUpload()文件上传 路径upload/ 自动重命名 ///FileDownload()文件下载 调用方法如 FileDownload(Response,Server,文件虚拟路径) ///FileTxtWrite()写入TXT文本 给出要...

    KODExplorer 芒果云-资源管理器

    - 弹出层中的弹出层关闭,父窗口失去焦点问题。 - 代码中grunt部分代码拆分开,放到程序外面;提交到git、osc - 桌面:删除alert enter快捷键删除 - install 检测 加入跳过,(只判断用到的函数) 加入多语言 - ...

    net实用类50超级实用方法赠分页

    ///FileSize()获取上传文件大小 ///FileUpload()文件上传 路径upload/ 自动重命名 ///FileDownload()文件下载 调用方法如 FileDownload(Response,Server,文件虚拟路径) ///FileTxtWrite()写入TXT文本 给出要...

    net实用类50超级实用方法赠分页分页控件强大的分页

    ///FileSize()获取上传文件大小 ///FileUpload()文件上传 路径upload/ 自动重命名 ///FileDownload()文件下载 调用方法如 FileDownload(Response,Server,文件虚拟路径) ///FileTxtWrite()写入TXT文本 给出要...

    .net50个常用方法简单华丽的分页控件功能大的分页控件 50个实用方法

    ///FileSize()获取上传文件大小 ///FileUpload()文件上传 路径upload/ 自动重命名 ///FileDownload()文件下载 调用方法如 FileDownload(Response,Server,文件虚拟路径) ///FileTxtWrite()写入TXT文本 给出...

    xheditor-1.1.14

    说明:控制弹出窗口是否显示上方的标题栏,默认为显示,若需要显示一个更定制个性化的iframe窗口,可通过此参数隐藏上方的标题栏 upBtnText:上传按钮的文字 参数值:任意字符串,默认值:“上传” 备注:1.0.0 beta2...

    JSP实用技巧集合,jsp编程的一些小技巧总结

    70. jsp直接弹出下载框下载文件? 71. 配置数据连接池和数据源(Tomcat)? 72. 点击图1变为图2? 73. JSP中显示图片的方法之一? 74. int转为Integer的方法? 75. 请求jsp页面禁止缓存方法? 76. select选中其中的值自动...

    Editplus 3[1].0

    $(FilePath) 文件路径(文件全名,含目录和文件名) $(FileDir) 文件目录(不带文件名) $(FileName) 文件名(不带目录) $(FileNameNoExt) 不带扩展名的文件名(不带目录) $(FileExt) 扩展名(当前文件) $...

    JAVA上百实例源码以及开源项目

     Java zip压缩包查看程序,应用弹出文件选择框,选择ZIP格式的压缩文件,可以像Winrar软件一样查看压缩文件内部的文件及文件夹,源码截图如上所示。 Java 数字签名、数字证书生成源码 2个目标文件 摘要:JAVA源码,...

    ASP200问.EXE

    46.如何用Cookie实现仅弹出一次同样的窗口 48.如何清除页面缓存 49.如何获取用户浏览器信息 50.如何获取用户真实的IP地址 52.如何判断网站的虚拟物理路径 53.如何解决URL含有特殊字符引发的错误 第4章 ASP组件 55....

    java源码包---java 源码 大量 实例

     Java zip压缩包查看程序,应用弹出文件选择框,选择ZIP格式的压缩文件,可以像Winrar软件一样查看压缩文件内部的文件及文件夹,源码截图如上所示。 Java 数字签名、数字证书生成源码 2个目标文件 摘要:JAVA源码,...

    java源码包2

     Java zip压缩包查看程序,应用弹出文件选择框,选择ZIP格式的压缩文件,可以像Winrar软件一样查看压缩文件内部的文件及文件夹,源码截图如上所示。 Java 数字签名、数字证书生成源码 2个目标文件 摘要:JAVA源码...

Global site tag (gtag.js) - Google Analytics