Javascript in external file not working

70 views
Skip to first unread message

Loai Ghoraba

unread,
Nov 26, 2012, 6:04:39 PM11/26/12
to django...@googlegroups.com
Hi all

When I have a script like this:
<script> window.onload=function f(){} </script> it is working fine. but when I create an external js file and put it within the static directory, and call the function like this
<script  src="{{STATIC_URL}}js/myjs.js"></script>
<script> window.onload=f </script>

It is not working at all. (by the way the url is mapped correctly to the js file "I tested it via viewing the source of the web page")
 
Any idea?

Bill Beal

unread,
Nov 26, 2012, 8:13:26 PM11/26/12
to django...@googlegroups.com
I think {{STATIC_URL}} should have spaces, like {{ STATIC_URL }}.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/m9Dv6qeozQQJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Pankaj Singh

unread,
Nov 26, 2012, 9:02:38 PM11/26/12
to django...@googlegroups.com
This appears to be a javascript issue, because your code should only
fail if window.load is fired before f is defined.

But you say that, url for js file works. Please use Firebug addon in
Firefox to see javascript errors.

-- Pankaj

Loai Ghoraba

unread,
Nov 27, 2012, 4:47:42 AM11/27/12
to django...@googlegroups.com
Thanks a lot guys, I found that there was a compile error, when copying I forgot the closing bracket :)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
Reply all
Reply to author
Forward
0 new messages