`

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实现弹出窗口以及获取上传文件的全路径。 首先,我们来讨论如何使用JS创建一个弹出窗口。通常,我们会结合HTML和CSS来实现。在HTML中,我们可以创建一个隐藏的`&lt;form&gt;`元素,...

    js弹出保存对话框

    ### JS弹出保存对话框知识点解析 #### 一、概述 在Web开发中,有时候我们需要让用户选择一个文件夹路径来保存文件,例如在导出数据为CSV或Excel时。JavaScript本身并不支持直接创建文件选择器或者保存对话框,但...

    js获取上传文件的绝对路径实现方法

    5. 在弹出的"安全设置"窗口中找到"其他"类别。 6. 找到"将文件上载到服务器时显示文件目录路径"选项。 7. 将其设置为"启用"状态。 8. 点击"确定"保存设置并重新启动IE浏览器。 完成上述操作后,当用户使用上传文件...

    asp怎样上传文件到指定的文件夹,并在access中记录路径

    **index.asp** 代码片段展示了如何使用 JavaScript 弹出一个新窗口来打开文件上传页面 (`uploadprod.asp`)。这部分代码利用了 JavaScript 的 `window.open` 方法: ```html &lt;script language="JavaScript" type=...

    完整版弹出下载窗口.rar

    标题中的“完整版弹出下载窗口”通常指的是一个软件或者网页功能,允许用户通过点击按钮或链接触发一个弹出窗口来下载文件。这个过程涉及到Web开发、前端编程、用户体验设计等多个IT领域的知识点。 1. **Web开发**...

    大名鼎鼎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...

    JS点击某个图标或按钮弹出文件选择框的实现代码

    接下来,定义了getFilePath函数,该函数用于获取用户选择的文件路径。这里使用了jQuery的attr方法来获取隐藏的file元素的value属性值,并通过alert弹出。尽管在现代Web应用中直接通过脚本获取用户文件系统路径并不是...

    grails中的上传,下载

    - **上传按钮**:在GSP页面上添加上传按钮,触发弹出窗口进行文件选择和上传。 - **使用JavaScript**:通过JavaScript函数`upLoadWindow()`,打开新的页面用于文件选择,同时向服务器发起上传请求。 - **上传页面**...

    asp多文件上传源码

    - **分析**:该页面通过JavaScript弹出一个新窗口,打开`reg_upload.asp`页面进行图片上传操作。 2. **reg_upload.asp**:提供上传图片的表单界面。 ```html &lt;title&gt;&lt;/title&gt; ;charset=gb2312"&gt; ...

    swfupload使用org.apache.commons.fileupload 实现上传文件

    SwfUpload 是一个开源的Flash上传组件,它允许用户在网页上实现文件的批量上传,而无需使用表单提交或JavaScript弹出窗口。这个组件利用了Flash技术,可以在不刷新页面的情况下实现文件上传,提供了良好的用户体验。...

    jQuery网页右下角弹出视频

    ASP.NET提供了诸如HttpPostedFileBase对象来处理文件上传,以及Server.MapPath方法来获取服务器上的文件路径。 总结起来,"jQuery网页右下角弹出视频"涉及的知识点包括:jQuery的选择器和API使用、DOM操作、事件...

    asp带进度条批量上传

    3. **窗口特效**:为了提供良好的用户体验,通常会使用弹出窗口来展示上传界面和进度条。这需要HTML和CSS来构建窗口样式,可能还会用到JavaScript库如jQuery UI或Bootstrap来实现更复杂的动画效果。窗口特效可以使...

    Jquery thickbox回传值实例

    当文件上传完成后,我们需要获取文件路径或URL,并将其传递回主页面。 在Thickbox内容页(例如`your_content.html`),可以有以下代码: ```html 上传 $(document).ready(function() { $('#uploadButton')....

    js选择文件夹

    该方法通过创建一个ActiveX对象(`Shell.Application`),利用其提供的方法`BrowseForFolder`来弹出系统文件夹选择对话框,并获取用户选定的文件夹路径。 #### 二、代码分析 ##### 1. HTML结构 HTML部分定义了一...

    商用版本文本编辑器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...

    基于PHP的瀑布流图片点击弹出大图片源码.zip

    Lightbox是一种在网页上以全屏模态窗口显示多媒体内容(如图片或视频)的常见方法,当用户点击小图时,大图会在当前页面上弹出。在PHP中,我们可能需要创建一个HTML模板,包含大图和必要的JavaScript代码,以实现...

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

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

Global site tag (gtag.js) - Google Analytics