如何检查用户是否是第一次点击JSP中的链接?

发布于 2024-12-10 21:13:10 字数 1240 浏览 0 评论 0原文

我的网络应用程序结构如下:

带有 n 个链接和选项卡式结构的主页

每个链接都会在主页的选项卡式结构中打开一个选项卡,并使用 ajax 在选项卡中加载页面

因为每个页面都需要不同的 javascript 函数(主要用于init 部分)在ajax加载的完整功能中我加载.js脚本并执行它。

现在我有一个问题:我需要在这些选项卡之一中有一个文本编辑器,所以我选择了 TinyMCE。它需要初始化,但只能初始化一次,否则会崩溃。 现在我需要一种方法来检查用户打开选项卡的次数。

我在 jsps 中寻找变量范围,并找到了“Session Scope”。我知道服务器端会话变量无法从客户端访问,但是jsp中的这些会话范围变量是客户端,所以我想我会使用会话变量jsp端来计算用户单击链接的次数。

在主jsp中,我放置:

<c:set var="timesEditorLoaded" value="0" scope="session" />

打开编辑器的链接是:

<a tabindex="22" id="proposte_propostaTesto_a" class="colorbox" href="${pageContext.request.contextPath}/editorPopup?hiddenCallerFormElementId=proposte_propostaTesto&" onClick="incrementEditorVariable();">Apri editor</a>

函数incrementEditorVariable()是:

<script type="text/javascript">
function incrementEditorVariable()
{
    alert("incrementEditorVariable: " + timesEditorLoaded);
    timesEditorLoaded = timesEditorLoaded + 1;
}
</script>

但在Chrome中我得到:

Uncaught ReferenceError: incrementEditorVariable is not defined

如果我将函数incrementEditorVariable放在外部.js文件中,我如何访问存储在的会话变量jsp? 有办法做到这一点吗? 先感谢您!

I have my webapplication structured like this:

Main page with n links and a tabbed structure

Every link opens a tab in the tabbed structure of the main page and with ajax loads the page in the tab

Because every page needs different javascript functions (mainly for the init part) in the complete function of the ajax load I load the .js script and execute it.

Now I have a problem: I need to have a text editor in one of these tabs, so I chose TinyMCE. It needs to be initialized, but only once, otherwise it will crash.
Now I need a way to check how many times the user opened the tab.

I was looking for variables scopes in jsps, and found "Session Scope". I know server side session variables cannot be accessed from clients, but these session scope variables in the jsp are client side, so I thought I would be using a session variable jsp side to count how many times the user clicks on the link.

In the main jsp I put:

<c:set var="timesEditorLoaded" value="0" scope="session" />

The link which opens the editor is:

<a tabindex="22" id="proposte_propostaTesto_a" class="colorbox" href="${pageContext.request.contextPath}/editorPopup?hiddenCallerFormElementId=proposte_propostaTesto&" onClick="incrementEditorVariable();">Apri editor</a>

The function incrementEditorVariable() is:

<script type="text/javascript">
function incrementEditorVariable()
{
    alert("incrementEditorVariable: " + timesEditorLoaded);
    timesEditorLoaded = timesEditorLoaded + 1;
}
</script>

but in Chrome I get:

Uncaught ReferenceError: incrementEditorVariable is not defined

If I put the function incrementEditorVariable in an external .js file, how can I access the session variable stored in the jsp?
Is there a way to accomplish this?
Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦行七里 2024-12-17 21:13:10

您可以修改用户单击按钮时的 onclick 事件。看起来有点蹩脚,但如果 onclick 只关心一件事,就可以解决所有问题。

You can modify the onclick event when the user clicks on the button. Seems a little crappy, but can solve everything if the onclick has only one thing to care about.

旧情勿念 2024-12-17 21:13:10

我最终向 MVC 架构添加了一个会话变量,并完成了这项任务。我这样做是为了尝试修复一个错误,我完成了计算用户单击链接的次数以防止初始化n次TinyMCE实例,但这并没有解决菜单保持打开状态的问题。

I ended up adding a session variable to the MVC architecture, and accomplished this task. I was doing this to try to repair a bug, I accomplished to count the number of times the user clicked on a link to prevent to init n-times a TinyMCE instance, but this didn't solve the problem of the menus staying open.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文