使用 window.open() 打开文件时传递 url 参数(从 ColdFusion 页面)

Passing url parameters when opening a file w/ window.open() (from a ColdFusion page)

本文关键字:url 参数 页面 ColdFusion 文件 open window 使用      更新时间:2023-09-26

在文件(.doc)上调用window.open()时,有没有办法将url参数传递给Web服务器?

我的问题是当我调用 window.open 打开一个文件(在 c:)从 JavaScript 函数中,向(Coldfusion) Web 服务器发出请求以重新加载当前页面(这很奇怪,我什至没有使用提交类型输入):

查看附件.cfm

function viewFile(selectbox) {
    var selItem  = selectbox.options[selectbox.selectedIndex].text;
    var selValue = selectbox.options[selectbox.selectedIndex].value;
    var filePath = selValue + '''' +  selItem;
    window.open(filePath);
}
<cfform name="gridForm"  method="post">
<table>
    <tr><td>
        <cfset destination = expandPath("./cold_case_files")>
        <cfdirectory directory="#destination#" action="list" name="fileList" type="file" >  
        <select id="fileName" name="fileName">
            <cfoutput>
                <cfloop query="fileList">
                    <option value="#directory#" >#fileList.Name#</option>
                </cfloop>
            </cfoutput>
        </select>  
    </td></tr>
    <tr><td>
        <input type="image" src="btn.jpg" name="view" onClick="viewFile(fileName);return false;" />
    </td></tr>
</table>
</cfform>

这是一个问题 b/c 在整个文档中都有对 url 参数的 coldfusion 引用(在首次加载页面时传入),这会导致"找不到 url 参数"异常:

var ProjID = <cfoutput>#url.ProjID#</cfoutput>;

我尝试使用 name 参数的各种值调用 window.open 以防止 viewAttachments.cfm 重新加载:

window.open(URL,名称,规格,替换)

  • _blank - URL 加载到新窗口中。这是默认值
  • _parent - URL 加载到父框架中
  • _self - URL 替换当前页面
  • _top - URL 替换可能加载的任何框架集

所以我的两个选项要么是防止在触发 window.open() 时重新加载调用页面,要么弄清楚如何将 url 参数传递给调用。

真正奇怪的是,该页面在我从中复制代码的生产站点上运行。上层告诉我,这不是 Web 服务器配置或应用程序设置问题,所以我不知所措。

格拉齐。

(来自评论...

您正在传入文件的物理路径,即c:'path'someFile.docx.相反,您需要使用指向服务器上该文件的 URL,即 http://yourserver/path/to/someFile.docx .

就原始代码而言,如果它有效,我会感到惊讶。并非所有浏览器都支持访问本地文件。那些通常需要特殊权限和语法,即 "file:///.... ,代码没有使用。(注意:HTML5 功能不同)。另外,无论如何,这些文件都不是本地的。 它们位于 CF 服务器上。但是,浏览器将在本地客户端计算机上查找。所以它几乎总是会失败。除非您在浏览器中打开该页面 - 在 CF 服务器本身上 - 您的普通用户显然无法做到这一点;-)