admin管理员组

文章数量:1400762

I am currently using Confluence 4.3 and I'm trying to add either an HTML button or HTML link that will invoke a javascript function.

How can this be achieved?

Specifically, there is a file called "searchpanel.vm" within Confluence which is a simple velocity template that defines criteria used to refine your confluence searches.

I wish to a button in the search panel that will invoke a javascript function. How do I do this?

I am currently using Confluence 4.3 and I'm trying to add either an HTML button or HTML link that will invoke a javascript function.

How can this be achieved?

Specifically, there is a file called "searchpanel.vm" within Confluence which is a simple velocity template that defines criteria used to refine your confluence searches.

I wish to a button in the search panel that will invoke a javascript function. How do I do this?

Share Improve this question asked Dec 28, 2012 at 5:08 user1068636user1068636 1,9497 gold badges36 silver badges63 bronze badges 1
  • 1 you can just use a script tag and put a function call inside it, or use velocity to generate onload for document. there is nothing special to invoke js from velocity. – SriN Commented Dec 28, 2012 at 17:04
Add a ment  | 

2 Answers 2

Reset to default 4

There is no special notation for writing Javascript in Velocity. Just write as you normally do in any HTML file. An example would be :

    <form>
    #if ($searchVisible)
        <div id = "searchLinkContainer" >
            <a href="javascript:searchFunction()">Click here</a> to search.
        </div>  
    #end    
    </form>
    <script language="JavaScript" type="text/javascript">   
        function searchFunction () {
            //Do search
        }
    </script>

Note that if you include the tag inside a conditional statement in Velocity and it doesn't get traversed, the script will not be available in the HTML page.

Velocity is just a templating language/engine, which can print whatever you want. Just write the HTML that you would normally use regardless of the fact that you're in a .vm file.

本文标签: How do you invoke javascript function from an apache velocity *vm fileStack Overflow