简体   繁体   English

如何在HTMLHELP(.CHM文件)的页面之间传递参数

[英]How to pass parameters between pages in HTMLHELP (.CHM files)

I need to create a Windows help file where there are many topics which are very similar, just differing in detail. 我需要创建一个Windows帮助文件,其中有许多非常相似的主题,只是细节有所不同。 Instead of creating a page for every combination (about 40 per topic!), I want to use Javascript to modify the detail, but I need to pass parameters to each page. 我不想使用每种组合创建页面(每个主题大约40个!),而是想使用Javascript来修改细节,但需要将参数传递给每个页面。

I tried to use the URL search argument: 我尝试使用URL搜索参数:

<a href="page.htm?argument">Page</a>

This works nicely in standard HTML files in a browser, even in the HTML Help Workshop, but as soon as it is compiled in a .CHM file, I get an error page stating: This page can't be displayed. 在浏览器中的标准HTML文件中(甚至在HTML帮助工作室中),该方法也能很好地工作,但是一旦将其编译为.CHM文件,我将收到一个错误页面,指出:该页面无法显示。

I tried to put "page.htm?argument" in the .HHP but that does not work either. 我试图将“ page.htm?argument”放在.HHP中,但这也不起作用。

Some information for you adding eg .css or .js file to the [FILES] section like described below. 如下所述,您可以在[FILES]部分中添加.css或.js文件的一些信息。

The help compiler tries to pull into the .chm all local files that are directly referenced in the HTML files, whether they be other HTML files, graphics, cascading style sheets, etc. Make sure your script file and CSS is compiled into your CHM too. 帮助编译器会尝试将HTML文件中直接引用的所有本地文件提取到.chm中,无论它们是其他HTML文件,图形,级联样式表还是其他文件。请确保您的脚本文件和CSS也已编译到CHM中。

To make extra certain that all graphics (and Cascading Style Sheets like *.css) are compiled into the .chm, you can list them in the [FILES] section of your project (.hhp) file. 为了更加确定所有图形(和级联样式表,例如* .css)都已编译到.chm中,可以在项目(.hhp)文件的[FILES]部分中列出它们。 With HTML Help Workshop, the procedure is as follows: 使用HTML Help Workshop,过程如下:

1) Open the project file in HTML Help Workshop. 1)在HTML帮助工作室中打开项目文件。

2) Click the Add/Remove Topic Files button on the Project tab. 2)单击“项目”选项卡上的“添加/删除主题文件”按钮。

3) Click Add. 3)点击添加。

4) In the File Name field, type *.gif (or *.jpg). 4)在“文件名”字段中,输入* .gif(或* .jpg)。

5) Click Open, and then select eg the graphics files to add. 5)单击打开,然后选择要添加的图形文件。

If you want, you can use wildcards in the [FILES] section to specify every file in a given directory. 如果需要,可以在[FILES]节中使用通配符指定给定目录中的每个文件。 For example: 例如:

[FILES] html*.htm images*.gif css\\foobar.css [文件] html * .htm图片* .gif css \\ foobar.css

Of course, you'd have to edit the project file in a text editor such as Notepad to do this and compile again. 当然,您必须在文本编辑器(例如记事本)中编辑项目文件,然后再进行编译。 Note that all files must be on the project file "folder level" or in subfolder structure level. 请注意,所有文件都必须位于项目文件“文件夹级别”或子文件夹结构级别。

I solved my problem by using the window.name property. 我通过使用window.name属性解决了我的问题。 Passing two parameters: 传递两个参数:

<script>window.name = "p1=Par1;p2=Par2";</script>
<a="href=page.htm>Goto page</a>

In page.htm: 在page.htm中:

<head>
<script language="JavaScript">
function getName(c_name) {
    var c_start,c_end;
    if (window.name.length > 0) {
        c_start = window.name.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = window.name.indexOf(";", c_start);
            if (c_end == -1) c_end = window.name.length;
            return unescape(window.name.substring(c_start, c_end));
        }
    }
    return "";
}

</script>
</head>
<body>
<H2 id="h2id"></H2>
<script>
document.getElementById("h2id").innerHTML = 'P1: '+getName("p1")+ ' P2: '+getName("p2");
</script>
</body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM