Browser Widget and external JavaScript files

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
folko
Posts: 3
Joined: Thu Apr 12, 2018 12:44 am

Browser Widget and external JavaScript files

Post by folko » Thu Apr 12, 2018 1:29 am

Hi Livecode community,

This is my first post. So please forgive me if my question should belong to another thread.

I am new to Livecode, coming from JavaScript, AS3 etc. I did some experiments with the browser widget. I successfully managed the 2-directional communication (LC to JS and JS to LC). What i try to achieve: building a LC-Standalone Application capable of "cleaning up" SVG-files located in local html files. This works fine already.

The next step would be to set animation params and play the SVG-animation within the browser widget. This doesnt work well.

Here is my problem:

The final animation is done in JavaScript (own script, no jQuery).
To keep the HTML/JavaScript clean, the JavaScript files are kept separated (external files)
When tested purely in a "normal" Browser, animations work as aspected. So: the JavaScript is fine.
But: when loaded into the browser widget, animations wont play.

Testing:
This also happens, when using JS frameworks. In this case: Snap.js

More testing:
Instead of using an external JavaScript file, i copied that into the main html file. Bingo: now this works also in the browser widget !?

So my question is:

- Does the "liveCode"-Object (LCs extension to the browser) interferes with external .js files ?
- Is this a known issue?
- work arounds?
- btw. i am using the community edition

Thanks in advance, Folko

Klaus
Posts: 13823
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Browser Widget and external JavaScript files

Post by Klaus » Thu Apr 12, 2018 1:48 pm

Hi Folko,

welcome to the forum! :D

Hm, sounds like a path problem. Are you also using external HTML files?
If yes, put the JS files into the same folder as the html.

Unfortunately I do not know what the browser widget thinks is the current "defaultfolder".
On what platform are you experiencing this in a standalone?
Does it work in the IDE?

Best

Klaus

folko
Posts: 3
Joined: Thu Apr 12, 2018 12:44 am

Re: Browser Widget and external JavaScript files

Post by folko » Thu Apr 12, 2018 6:31 pm

Hi Klaus,

thank you for answering.

I did some further investigations: external js files do not cause the problem per se. It´s the browsers window object!

Explanation: i am used to attach variables or objects to the top level window object. This works in all browsers. But it seems the LC browser does not like this.

So i have to reorganize my javascript.

Thanks again, Folko

folko
Posts: 3
Joined: Thu Apr 12, 2018 12:44 am

Re: Browser Widget and external JavaScript files

Post by folko » Sat Apr 14, 2018 8:08 pm

Ok. There is a much more simpler explanation:

When using the browser widget just to load/show html, it works as expected. Also, external javascript files work.

What i did: load the html into a variable, manipulate things, put the result into the widget. This works partly. In this case, the html content is located in memory. Therefore, links to external javascript files might not work. I think, there is no way to "force" loading the externals, is it?

Workarounds:
- First save the result back to file. Then reload it.
- Or: copy the external js into the html variable temporarily.

Folko

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”