Quantcast

function javascript in all cell

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

function javascript in all cell

debimax
This post was updated on .
hello

(excuse me for my bad  english)
Il have un function  in cell   javascript

cell1:  **************************
%%javascript
function afficher(msg)
 {
   element.append(msg);
 }
 afficher("hi")
********************************


it's  good and i have message "hi"  but if i try function afficher in a other cell
cell2: ***************************
%%javascript
afficher("hi")
*********************************

it's no good and i have  error:   NameError: name 'afficher' is not defined

is it possible to use function afficher in all cell.

thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: function javascript in all cell

Matthias Bussonnier
Hi debimax,

First I'd like to let you know that ipython-user is deprecated and
ipython-dev(at)scipy.org is prefered we tend not to segregate devs and
user. If you are advanced enough to code in IPython, you are advanced
enough to modify it.

Also if english is not your prefered language and you need to ask some
pieces in another language, feel free to do so, I myself started here
a couple of years ago barely able to align two words, and probably
still do a lot of mistakes.

The reason for the behavior you see is that each of the javascript
cell is executed in a different context in which locals and globals
are different. `element` is a magic element which is injected. So when
you execute things in the first cell, what you defined there will not
exist in others unless you explicitly attach it to a global object.
Usually in JS you will attach to the `window` object (If I Remember
correctly).

So if you do something like `window.afficher = afficher`, then it
should work, `afficher` will be search in the global namespace if not
found locally.

Hope that helps.
--
Matthias





On Fri, Dec 23, 2016 at 9:17 AM, debimax <[hidden email]> wrote:

> hello
>
> (excuse me for my bad  english)
> Il have un function  in cell   javascript
>
> cell1:  **************************
> %%javascript
> function afficher(msg)
>  {
>    element.append(msg);
>  }
>  afficher("hi")
> ********************************
>
>
> it's  good and i have message "hi"  but if i try function afficher in a
> other cell
> cell2: ***************************
> %%javascript
> afficher("hi")
> *********************************
>
> it's no good and i have  error:   *<it> NameError: name 'afficher' is not
> defined</it>*
>
> is it possible to use function /afficher/ in all cell.
>
> thanks
>
>
>
> --
> View this message in context: http://python.6.x6.nabble.com/function-javascript-in-all-cell-tp5205651.html
> Sent from the IPython - User mailing list archive at Nabble.com.
> _______________________________________________
> IPython-User mailing list
> [hidden email]
> https://mail.scipy.org/mailman/listinfo/ipython-user
_______________________________________________
IPython-User mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: function javascript in all cell

debimax
hi matthias


thank you very much, i have solve my problem with window.afficher = afficher
Loading...