0
Answered

Javascript isn’t running when i preview html file.

cdeckard 6 years ago in iPad updated by Alexander Blach (Developer) 6 years ago 5

No output on JavaScript console.  Preview in safari doesn’t do anything.

This project works under safari on my Mac.

intuitive software this not is

Under review

There is most likely a problem somewhere in your HTML or JavaScript file.

Can you please send me the project by email to support@textasticapp.com so I can have a look at it?

You can also try to run it through the HTML validator at https://validator.w3.org

Hi Alexander, that’s likely a matter of perspective (especially is an environment as standards-free as JavaScript).  It (the html) did fail a few nit picky things like no <title> or <DOCTYPE> tags — but the page is rendering ok, so I don’t think these are the issue.  It’s not running JavaScript.  Does Textastic support es6 modules (I couldn’t find this in the docs)?  In particular, I have the following line in the html file:

<script type=“module” src=“./myScript.js”></script>

The ‘myScript.js’ file has es6 import directives.

Are you using WebKit to render html?  Under OSX, safari requires a webserver for es6 modules; otherwise it throws errors on the console.  However, I don’t get any output on the Textastic js console .. . .


Any ideas?

Thanks,

Chris Deckard

Seattle, wa



Textastic uses WKWebView which is the same WebKit engine that is used by Safari.

WebKit does support ES6 modules in the latest iOS versions. Also, Textastic does run a local web server. 


If you send me sample project that doesn't work, I can have a look at it.

Alexander, thanks for the info.  I made a quick test project, and the “dependency” chain seems to be working ok.  Now, my guess is that it’s because the files aren’t on the local file system (I created files via Textastic on the local file system for the test project).  The project (that is not working) is in my Dropbox.  I’m able to open the files in Textastic, but my guess is that _import_ directives don’t know where to “look” for the file.
I say this because the .css file isn’t having an effect.  The two relevant lines are:


<link rel=“stylesheet” type=“text/css” href=“./diagrama.css”>
<script type=“module” src=“./diagrama.hs”></script>

I have both the linked files open in Textastic (by Using Open>Browse>Dropbox).

(FWIW, I’m unable to copy from Textastic and paste into the forum text editor via safari/iPad — also I lose the cursor in this text editor when I change focus)


 I did take a look at this document:

https://www.textasticapp.com/v7/manual/integration_other_apps/external_files_folders.html

From what I gather from the above linked document, it should work.  Thoughts?

Cheers,

Chris


Answered

Hello,

when you use the "Open…" command to open a file from Dropbox, Textastic only has access to that single file. It cannot access other files in Dropbox. Even if you open both files, Textastic does not know that they are from the same location.

Please use the built-in Dropbox client instead to download your project to "Local Files" or "iCloud". Then the preview will work as expected.

This is also explained in the document you linked to:

If you plan to use the built-in web preview to preview a HTML file with external JavaScript, CSS, or image files, it is recommended to use one of the built-in clients for (S)FTPWebDAVDropbox, or Google Drive to download your website files first and edit and preview them locally. If you open a single file with the document picker, linked files cannot be accessed by the web preview due to the iOS security sandbox that limits an app’s access to files in other apps.

Have a look at the following topics in the manual to see how you can download files from Dropbox:

https://www.textasticapp.com/v7/manual/remote_servers/remote_file_transfer_screen.html

https://www.textasticapp.com/v7/manual/remote_servers/dropbox.html

https://www.textasticapp.com/v7/manual/remote_servers/uploading_downloading.html

https://www.textasticapp.com/v7/manual/remote_servers/quick_upload_download.html

Sorry that I didn't know right away what was going on.