gpt4 book ai didi

java - 使用 ZK : How to add a script into the head tag from java?

转载 作者:行者123 更新时间:2023-11-29 18:09:05 25 4
gpt4 key购买 nike

使用 ZK,我尝试以编程方式将脚本添加到 header 标记中。

我该怎么做?

最佳答案

终于找到解决办法了! ZK 的论坛有人给出了这些可能的解决方案:

http://forum.zkoss.org/question/96845/using-zk-5-how-to-add-a-script-into-the-head-tag-from-java/

“我知道两种方法:

1.将javascript文件的声明放入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。在java代码中添加手册:

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.");
}

来自 api:

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

添加将在 head 元素内和 ZK 的默认标签之前生成的标签。例如,

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

关于java - 使用 ZK : How to add a script into the head tag from java?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29102667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com