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!
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.