Calling JavaScript function in between the URL Query String
I am trying to call one javascript function in between my query string in the following manner but its not working......Can anybody point out whether i am doin it correctly or not? My motive is to remove special characters(#,& etc.) from one of the parameters(appName) in my query string.开发者_如何学JAVA...........plz help!!
<a target="_self" onmouseout="hideTooltip()" onmouseover="showTooltip(event,'click on the name for additional details');return false" class="tip" href='<%=request.getContextPath()%>/index.jsp?page=myhome&type=details&appName=javascript:escape('<%=adMetricsVO.getApplicationName()%>')&Id=<%=bean.getID()%>'><%= bean.getName()%></a>
That's very wrong. (and impossible to do as you're attempting)
You should escape the getApplicationName()
on the server.
You need to URL-encode it, then attribute-encode it.
That's not going to work because the Javascript interpreter won't be involved with the ordinary "click" behavior of the element. In other words, Javascript is never going to see that "href" value.
To make that work, you could either escape the application name on the server, or else put the URL together in a separate piece of Javascript that you wire up to the window "load" event, or something like that.
Alternatively you could have the "click" handled by a Javascript handler that makes the URL and reloads the page.
精彩评论