Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call javascript function from django

Can a javascript function be called from django HttpResponseredirect or some other django function

like image 385
Rajeev Avatar asked Dec 22 '22 18:12

Rajeev


1 Answers

If you're talking about in-browser js, no, django cannot call a javascript function. You've got django running on your server, and js running in the user's browser, and never the two shall mingle. Imagine if any old django site out there could reach into your browser at will and start doing things you didn't ask for!

What you can do is setup some sort of communication between the two, aka AJAX. Have the javascript side periodically poll the django server for information, at which point django can tell the javascript what to do (do this function, run that process). Or figure out how to do comet.

OTOH, If you're talking about server-side js, sure, why not? It'd be the same as calling a perl function, or a ruby function (feed the interpreter the correct instructions to import/define/call that function).

like image 75
eternicode Avatar answered Dec 24 '22 06:12

eternicode