Skip to content
Advertisement

Jump to anchor in HTA file by command line specified parameter

Have cmd script help file in HTA format, it open every time user press key ‘h/H’ through script. Want to HTA jump to its specific part by context from where help is called (as usual in windows help files), but not sure how to do it. Thinking to pass anchor name as a parameter of mshta.exe, and than process in the beginning of HTA file…

Standard HTML defined anchors do not work in my case (maybe this does not work in HTA at all ??), but found working javascript way to do it.

JavaScript

Also found a way how to read passed parameters of mshta.exe, but it is in VBS and I have no idea how to transfer variable from VBS to javascript.

Anyone help me to make different language scripts to collaborate or propose other way to achive %subj%

Advertisement

Answer

About jumping to anchor:

For me, the regular way works just fine. I tried window.location = '#stuff', window.location.href = '#stuff' and window.location.hash = '#stuff', all of which had the desired effect.


About reading command line:

You should be able to use the same mechanism described in the linked tutorial – give the <hta:application> tag an id and then refer to it in JavaScript as and read its commandLine property:

JavaScript

In the command line, you get the whole thing as string, which can be problematic if you don’t know where the “argument 0” (the file path) ends and where the “actual” arguments start, since there can be spaces in the path.

A heuristic method that should work in all cases you encounter in the wild would be looking for .hta followed by an optional doublequote and then either end of string or some whitespace, and then only looking at the part that follows that.

JavaScript

If you wanted, you could then also split that part into individual arguments on whitespace (which would ignore quotes in arguments though – if quotes need to be respected, you’d need a function like this instead):

JavaScript

I think this isn’t even necessary in your case though, so you can simply do this:

JavaScript

If you try this, you’ll see you can do mshta c:pathtofile.hta third to jump to the third header for example.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement