gpt4 book ai didi

javascript - 如何使用 JavaScript 读取 HTML 链接的文件名?

转载 作者:行者123 更新时间:2023-12-02 23:27:59 24 4
gpt4 key购买 nike

我在某个文件夹中有一个 html 文件。该文件名为“file.html”。我在桌面或其他任何地方创建一个指向“file.html”的链接文件。链接文件的名称是例如“星期一”。

对于我的“file.html”,我使用一些 JavaScript 来过滤正在创建的表的某些行。

我的问题是:是否可以读取链接文件的“星期一”,打开原始文件并将“星期一”设置为现有下拉菜单的选定条目?如果是这样,我该怎么做?

我的 xslt 文件:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<html>
<head><title>Shared Secrets</title></head>

<body onload="JavaScript_Filter();">
<h1>Dokumentation Shared Secrets durch RD/UEA</h1>

<img style="position: absolute; top:80px; left:920px;" src="../logo/logo.jpg" alt="Logo RD/U"></img>

<table id="myTable">
<colgroup>
<col width="150" style="background-color:e2e2e2"></col>
</colgroup>
<tr style ="background-color:a5a5a5">
<th rowspan="2">plane
<select id="modelRangeDropdown" onclick="JavaScript_Filter()">
<option selected="selected">All</option>
<xsl:for-each select="logstore/plane">
<option>
<xsl:value-of select="Name" />
</option>
</xsl:for-each>
</select>
</th>
<th colspan="2" width="330">date</th>
<th rowspan="2">Secret
<input type="checkbox" id="identicalSecrets" onclick="JavaScript_Filter()"></input>
<label for="identicalSecrets">Hide identical secrets</label>
</th>
</tr>

<tr>
<th align="center" style="background-color:a5a5a5">begin</th>
<th align="center" style="background-color:a5a5a5">end</th>
</tr>
<xsl:for-each select="logstore/plane/trigger">
<tr>
<td align="center"><xsl:value-of select="../Name"/></td>
<td align="center"><xsl:value-of select="date"/></td>
<td align="center"><xsl:value-of select="date"/></td>
<td><xsl:value-of select="secret"/></td>
</tr>
</xsl:for-each>
</table>
<script type="text/javascript" src="JavaScript_Filter.js"></script>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

我的 JavaScript 代码:

// Just contains some filtering code... does not matter for my question

最佳答案

链接(至少在 Windows 中)是文件系统指针,当单击时,操作系统会根据底层资源的 mime 类型打开所引用的资源。所以,没有数据从链接传递到资源本身,因为这是由操作系统内部处理的。

我的第一个想法是创建一个名为“Monday.htm”的 HTML 页面,该页面只需转发到您的目标 HTML 页面,然后检查其引荐来源网址。但这不适用于本地文件:

A Referer header is not sent by browsers if:

  • The referring resource is a local "file" or "data" URI.
  • An unsecured HTTP request is used and the referring page was received with a secure protocol (HTTPS).

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer

第二个选项是将您的标识符添加到所请求资源的 URL 中,然后使用它进行识别。您的快捷方式页面将包含以下内容:

<html>
<head>
<meta http-equiv="Refresh" content="0;url=test.htm#Monday"/>
</head>
</html>

哈希符号#后面的单词将是我们的标识符。

在您的“主应用程序”中,现在只需检查参数:

<html>
<body>
<script>
var id = document.location.hash.substring(1);
alert(id);
</script>
</body>
</html>

不知道这是否适合您。

关于javascript - 如何使用 JavaScript 读取 HTML 链接的文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56647728/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com