I don't find how to execute javascript code placed in an external html file

30 views
Skip to first unread message

Fibo

unread,
Feb 17, 2012, 1:35:14 PM2/17/12
to iPhoneWebDev
The title is slightly obscure, so here is a more detailed description
of my problem.

1 - I have a main page (say A) which of course loads the css and js
needed for it.

2 - I make a href to an external file (say B). In this file B is some
html code AND javascript code working on this (B) html code. So I
cannot load and run the javascript directly from A, since html
elements from B are not visible when A is first loaded.

I'm certainly not the first doing that, so I presume there is some
working example somewhere...

Thx for your help
B.

Fibo

unread,
Feb 17, 2012, 2:43:36 PM2/17/12
to iphone...@googlegroups.com
B-) I forgot to mention that I am using iUI (in case there is a doubt!).

Sean Gilligan

unread,
Feb 17, 2012, 2:50:33 PM2/17/12
to iphone...@googlegroups.com, Fibo
iUI does not have this functionality built-in. However, there is an
extension called jit-loader.js (in the extensions sandbox) that will
load JavaScript along with an Ajax HTML fragment. There is a sample
app, too. You can view it here:
http://demo.iui-js.org/iui/ext-sandbox/jit-loader/test-jit-loader.html
It looks like the Google Maps functionality in the demo is broken, so
look at the "Test JavaScript Load -> Sub1" and " -> Sub2" pages.

Your other option is to have all your JavaScript loaded with "A", but
modify the JavaScript so that it can detect when "B" is loaded. (You
could use the iUI extension mechanism to do this)

Make sure you are using the latest version of iUI -- 0.40-beta2

-- Sean

Fibo

unread,
Feb 17, 2012, 9:08:01 PM2/17/12
to iphone...@googlegroups.com, Fibo
Thx Sean. Will explore the jit-loader route which seems simpler.

Fibo

unread,
Feb 22, 2012, 8:29:55 AM2/22/12
to iPhoneWebDev
The jit-loader route is really simple.

Just one warning for php and asp developers: be aware that the
javascript will be executed EACH time the external file is called. So
if you want to place an eventListener, use some logic to be sure to
place it only once!
Reply all
Reply to author
Forward
0 new messages