Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when saving after renaming empty html to HTA #275

Open
wshallum opened this issue Oct 26, 2022 · 6 comments
Open

Exception when saving after renaming empty html to HTA #275

wshallum opened this issue Oct 26, 2022 · 6 comments

Comments

@wshallum
Copy link

I'm having trouble saving when the empty file is renamed to .hta. The cause is HTA defaults to IE6 compatibility if not forced by the X-UA-Compatible meta tag and the use of .classList.add( in Messages.js here:

https://github.com/TiddlyWiki/TiddlyWiki/blob/536439d854dca721275ff1140e9b2d19711b168a/js/Messages.js#L23

is causing it to throw an exception (https://caniuse.com/classlist says that classList is only usable starting IE10).

It would help to either add the X-UA-Compatible meta tag or alternatively a) document what version of IE is supported and b) just display a message if it is too old.

(yes, I know it's barely documented that saving as HTA would work, it's only mentioned in this one tiddler):
https://github.com/TiddlyWiki/TiddlyWiki/blob/master/content/ServicePack2Problems.tid

I managed to work around this in my copy by manually adding the X-UA-Compatible meta tag.

@YakovL
Copy link
Contributor

YakovL commented Oct 26, 2022

Hey @wshallum , could you clarify the use-case, why renaming to .hta? I guess, you can also add the meta tag using the MarkupPreHead tiddler; the question I guess is whether it's a good idea to add the meta tag to the core or this is some very narrow case and it is good enough that you've found the solution for yourself.

@wshallum
Copy link
Author

Hi @YakovL - I renamed it to .hta because it seems to be the simplest way to get local saving working in Windows without any additional applications.

I tested using MarkupPreHead as you suggested but it seems to not work there (too late?). I needed to put it at the top of the <head> element ahead of the <script id="versionArea" for it to work.

I still think the general point about documenting what version of IE it expects to run on is valid.

@YakovL
Copy link
Contributor

YakovL commented Oct 27, 2022

Ah, so did I get you correctly?:

  1. you'd like to make "nice" saving (not "download" saving) to work on Windows (which version? XP?) without additional applications,

  2. you're doing this via IE (what version?),

  3. it works (via ActiveX, I suppose) if both TW's extension is changed to .hta and the X-UA-Compatible meta tag is added directly before script id="versionArea", like this (what value do you use? which ones work among those listed here and here?):

     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
     <head>
     <meta http-equiv="X-UA-Compatible" content="IE=___" />
     <script id="versionArea" type="text/javascript">
    

Once we're clear about the versions, I'll be able to look for some alternatives as changing extension doesn't sound like a friendly user experience anyway. If we put this into the core, we have to describe such usage in docs as well, so need to investigate the context.

@wshallum
Copy link
Author

wshallum commented Oct 27, 2022

  1. Yes that is correct. It's documented for TW5 here: https://tiddlywiki.com/static/Windows%2520HTA%2520Hack.html Both versions try to use the FileSystemObject ActiveX object.
  2. I'm using Windows 10 latest update (22H2) and the IE version is IE 11.
  3. I'm using this tag right now: <meta http-equiv="X-UA-Compatible" content="IE=11" /> - I can report that using IE=Edge also works (this is what TW5 is using and may be preferred as it does not lock it into an older version, when used in an HTA this runs it in IE11 mode for me).

The reason for changing extensions is that HTA is considered an "application" (as opposed to "web page") and still has access to the FileSystemObject for manipulating local files.

@YakovL
Copy link
Contributor

YakovL commented Oct 27, 2022

Oh wow, so it actually works not "inside IE", but as a standalone "app" (IE without tabs?). That's quite an interesting approach (in terms of UX)! I do agree that this should be documented (along with side effects, like UTF-16 encoding), and probably the meta tag should be added. I'll investigate this further later. Thanks for sharing! Probably worth sharing in the google group as well.

@wshallum
Copy link
Author

Thank you!

If you're interested: the UTF-16 encoding can be worked around in an HTA by using ADODB.Stream (docs) instead of Scripting.FileSystemObject e.g.

var s = new ActiveXObject("ADODB.Stream");
s.Type = 2; // adTypeText
s.Charset = "utf-8";
s.Open();
s.WriteText("\u2665", 0); // 0 = adWriteChar (no EOL)
s.SaveToFile("out.txt");
s.Close();

it works to save in UTF-8 however there's a UTF-8 BOM (EF BB BF) pasted in front of it.

$ xxd out.txt
00000000: efbb bfe2 99a5                           ......

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants