0

Using ZK 5: How to add a script into the head tag from java?

asked 2015-03-18 13:34:42 +0800

antoniojimenez gravatar image antoniojimenez
1

How can I do this?

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-03-18 15:24:28 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2015-03-18 15:27:51 +0800

I know two ways for that:

1.Put the declarartion of the javascript file in the lang-addon.xml

lang-addon.xml

<?xml version="1.0" encoding="UTF-8"?>

<language-addon>

. . .

<!-- 4. Path to Bootstrap javascript library -->
<javascript src="~./cyborg/less/bootstrap/js/bootstrap.min.js" type="text/javascript" charset="UTF-8" /> 

</language-addon>

2. Add manual in java code:

  if (view instanceof Window) {

        Window win = (Window) view;
        PageCtrl pc = (PageCtrl) win.getPage();
        pc.addBeforeHeadTags("<script type=\"text/javascript\">" + "(function(i,s,o,g,r,a,m)"
                + "{i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){"
                + "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();" + "a=s.createElement(o),"
                + "m=s.getElementsByTagName(o)[0];" + "a.async=1;a.src=g;m.parentNode.insertBefore(a,m)" + "})"
                + "(window,document,'script','//www.google-analytics.com/analytics.js','ga');" + "ga('create', "
                + this.trackingID + ", 'auto'); " + "ga('send', 'pageview');" + "</script>");

    } else {
        throw new UiException("This view model must be applied from a Window component.");
    }

from api:

void org.zkoss.zk.ui.sys.PageCtrl.addBeforeHeadTags(String tags)


Adds the tags that will be generated inside the head element and before ZK's default tags. For example, 

((PageCtrl)page).addBeforeHeadTags("");

best Stephan

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2015-03-18 13:34:42 +0800

Seen: 46 times

Last updated: Mar 18 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More