# call a javascript function from href link



## Mr.LLB

is this possible? 

i made a website with ajax,php. in certain part of the website, i am giving a link to the user. but i want the user to be loading a certain function of javascript on my page when they click on that link.

thx all.


----------



## andythepandy

Do you mean that when they click the link, you want a javascript function to run. If so:


Code:


<a href = "javascript:AnyFunction();">Click</a>

or


Code:


<a href="#" onclick="AnyFunction()">Click</a>


----------



## Mr.LLB

no. thats not what i meant.

ok, so theres my website. it has a js function on it that calls ajax & does what its suppose to.
the js function has a parameter (id).

i am sending people links in their emails. i want that link in the email to bring them to my website, automatically call the js function with the id i give it.

is this possible?

like www.ex.ca:javascript:loadProduct(1) <<<<< something like that.


----------



## Mr.LLB

so no body knows???


----------



## andythepandy

I don't think there is a way of doing exactly what you want but you can achieve the same by passing variables in the url then using either php or javascript on the page being loaded to use the variable passed and load a certain product
eg:


Code:


www.ex.ca/product.php?productId=1

Using php you have $_GET['productId'] and in javascript you could use window.location.href.split to read the value


----------



## Mr.LLB

thx andy

I was thinking about that too...i just thought maybe theres another way of doing it.


----------

