href="#" onClick="..."

Help
Mihai Arba
2005-07-15
2013-01-13
  • Mihai Arba
    Mihai Arba
    2005-07-15

    Is possible to add js code to links. I didn't find a way of doing this, so I rewrote ChartMapTag.writeOutLink method. If you know a more elegant solution please let me now.

        public void writeOutLink(Object linkGen, Dataset dataset, Writer out, ChartEntity ce) throws IOException {
            final String link = generateLink(dataset, ce);
           
            if (null != link) {
                // @arba added JS support for links - if starts with event (e.g. onClick = 'top.test()')
                if (link.startsWith("on")){
                    out.write("HREF=\"#\" "+link);
                }
                else{
                    final String href = ((HttpServletResponse) pageContext.getResponse()).encodeURL(link);
                    out.write("HREF=\"" + href + "\"");
                }
            }
        }

    Mihai

     
    • bertsylv
      bertsylv
      2005-07-15

      you can also return something like "javascript:..." in your generateLink method.
      it will generate a link like so: <a href="javascript:...>text</a>

      this has the same effect as an onclick attribute

       
      • jaypsXC5
        jaypsXC5
        2007-01-10

        How about for onmouseover?

         
    • dustin
      dustin
      2005-11-23

      This also works:

      public String generateLink(Object arg0, int series, int item) {
              return  "#\&quot; onClick=\&quot;alert('I am special');";
          }