# How to call javascript function in A site?

**URL:** <https://www.ruby-forum.com/t/how-to-call-javascript-function-in-a-site/183048>\
**Category:** Rails\
**Created:** [February 6, 2010, 10:39pm UTC](https://www.ruby-forum.com/t/how-to-call-javascript-function-in-a-site/183048 "2010-02-06T22:39:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![junyan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@junyan](https://www.ruby-forum.com/u/junyan)\
**Post date:** [February 6, 2010, 10:39pm UTC](https://www.ruby-forum.com/t/how-to-call-javascript-function-in-a-site/183048/1 "2010-02-06T22:39:52Z")

</div>

Hello, rubiers.  
now, I wanna call some functions in A site that was already  
implemented by another company. ( I don’t know internal… just  
nothing…)  
anyway, there are several javascript functions in there what I want  
call frequently in my ruby scripts.  
HOW DO I connect it and call it?  
Could you give me some examples?

for example)

hello, this is template!! click func\_a().... that is my goal to call in my scripts. thanks you.

---

<div class="post-metadata">

**Author:** ![junyan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@junyan](https://www.ruby-forum.com/u/junyan)\
**Post date:** [February 8, 2010, 3:24pm UTC](https://www.ruby-forum.com/t/how-to-call-javascript-function-in-a-site/183048/2 "2010-02-08T15:24:34Z")

</div>

Jun Y. wrote:

> hello, this is template!! click

This is a very old technique and I would not recommend using this style  
to call JavaScript functions.

Here is a more modern syntax:  
click

The most recent trend that is emerging is called “Unobtrusive  
JavaScript.” This new technique separates page behavior from page  
structure and presentation. Notice the “return false;” at the end of the  
onclick attribute.

> **[Unobtrusive JavaScript](https://en.wikipedia.org/wiki/Unobtrusive_JavaScript)**
>
> Unobtrusive JavaScript is a general approach to the use of client-side JavaScript in web pages so that if JavaScript features are partially or fully absent in a user's web browser, then the user notices as little as possible any lack of the web page's JavaScript functionality. The term has been used by different technical writers to emphasize different aspects of front-end web development. For some writers, the term has been understood more generally to refer to separation of functionality (th A ...

> func\_a().... that is my goal to call in my scripts. thanks you.

I would recommend putting your JavaScript functions in an external file  
inside “public/javascripts” and include them from inside :

 \<%= javascript\_include\_tag 'application' %\>

Or, if you want to also include the Prototype JavaScript libraries:

 \<%= javascript\_include\_tag :defaults %\>

Doing this will also include public/application.js along with the  
Prototype library.

---

<div class="post-metadata">

**Author:** ![junyan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@junyan](https://www.ruby-forum.com/u/junyan)\
**Post date:** [February 9, 2010, 12:51pm UTC](https://www.ruby-forum.com/t/how-to-call-javascript-function-in-a-site/183048/3 "2010-02-09T12:51:29Z")

</div>

actually, this is not what i want to do 😉  
sorry my poor english sentences made you misunderstand it.

okay.

if there is a general website like amazon, the site has plenty of  
javascript function.

the one of them is func\_a() function what I want to call it.

in my local,  
there is a ruby script to check some situation that does satisfy any  
conditions.  
by using this ruby script, I want to call func\_a() in a server-side.

is this possible?  
I think this is really easy functionality. but I could not find any  
solutions for me.

thanks for your concerns.

---

<div class="post-metadata">

**Author:** ![junyan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@junyan](https://www.ruby-forum.com/u/junyan)\
**Post date:** [February 9, 2010, 1:13pm UTC](https://www.ruby-forum.com/t/how-to-call-javascript-function-in-a-site/183048/4 "2010-02-09T13:13:55Z")

</div>

following code might help you

\<% if rails\_condition%\>

\<%end%\>

Regards,  
Naren
