Hello every one,

I have small problem. Can any one tell me how to get the url from an anchor tag dynamically. That is when i click on link the next coming url i need to send to a script can any one help me... My problem is when i click on a link the page should open with F11 functionality. This is some part of code. This a combination of JSP and JSF.

<!--
 ***********************************************************************************
 * $URL: https://source.sakaiproject.org/contrib/etudes/melete/tags/2.6.0/melete-app/src/webapp/melete/view_section.jsp $
 * $Id: view_section.jsp 56408 2008-12-19 21:16:52Z rashmi@etudes.org $  
 ***********************************************************************************
 *
 * Copyright (c) 2008 Etudes, Inc.
 *
 * Portions completed before September 1, 2008 Copyright (c) 2004, 2005, 2006, 2007, 2008 Foothill College, ETUDES Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 **********************************************************************************
-->
<html>
<head>

<link rel="stylesheet" href="rtbc004.css" type="text/css">
<title>Melete - Modules: Author Student View</title>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="" prefix="sakai" %>
<script type="text/javascript" language="JavaScript" src="js/headscripts.js"></script>
<script type="text/javascript">
<!--
function popup(url) 
{
 params  = 'width='+screen.width;
 params += ', height='+screen.height;
 params += ', top=0, left=0'
 params += ', fullscreen=yes'
 params += ', toolbar=no'
 params += ', location=no'
 params += ', menubar=no';

 newwin=window.open(url,'windowname4', params);
 if (window.focus) {newwin.focus()}
 return false;
}
// -->
</script>
</head>

<f:view>
<body onLoad="setMainFrameHeight('<h:outputText value="#{meleteSiteAndUserInfo.winEncodeName}"/>');">
<a name="newanchor"></a>
<h:form id="viewsectionform">       
<table height="470" border="0" cellpadding="20"  width="100%" bordercolor="#EAEAEA" style="border-collapse: collapse" >
<tr>
	<td vAlign="top" width="100%"> 
			<table  border="0" cellpadding="2" cellspacing="0" bordercolor="#EAEAEA" width="99%">
					<tr>
					<td colspan="2">
								<f:subview id="top" rendered="#{viewSectionsPage.instRole == true}">
												  <jsp:include page="topnavbar.jsp"/> 
									</f:subview>
								<div class="meletePortletToolBarMessage"><img src="images/preview.png" alt="" width="16" height="16" align="absmiddle"><h:outputText value="#{msgs.view_section_viewing_student}" /></div>	
					</td>
				</tr>
	<!--Page Content-->

	<tr>
		<td colspan="2" align="center">
					<f:subview id="topmod">
						<jsp:include page="view_navigate.jsp"/>
					</f:subview>
				<h:panelGroup id="bcsecpgroup" binding="#{viewSectionsPage.secpgroup}"/>
			</td>
</tr> 
<tr>
		<td colspan="2" align="left">  &nbsp;		</td>
</tr> 
<!-- <tr>
    	<td colspan="2" align="left">  
	        <h:outputText id="mod_seq" value="#{viewSectionsPage.moduleSeqNo}. " styleClass="bold style6" rendered="#{viewSectionsPage.autonumber}"/>
		<h:outputText id="modtitle" value="#{viewSectionsPage.module.title}" styleClass="bold style6"></h:outputText>
		</td>
</tr> -->

<!-- <tr>
		<td colspan="2" align="left">  
	        <h:outputText id="sec_seq" value="#{viewSectionsPage.sectionDisplaySequence}. " styleClass="bold style7" rendered="#{viewSectionsPage.autonumber}"/>
		  <h:outputText id="title" value="#{viewSectionsPage.section.title}" styleClass="bold style7"></h:outputText>     
		</td>
		
</tr> -->

<tr>
		<td colspan="2" align="left">  
				<h:outputText value="#{msgs.view_section_instructions} "  rendered="#{((viewSectionsPage.section.instr != viewSectionsPage.nullString)&&(viewSectionsPage.section.instr != viewSectionsPage.emptyString))}"  styleClass="italics"></h:outputText> <h:outputText id="instr" value="#{viewSectionsPage.section.instr}" rendered="#{((viewSectionsPage.section.instr != viewSectionsPage.nullString)&&(viewSectionsPage.section.instr != viewSectionsPage.emptyString))}"></h:outputText>     
		</td>
</tr> 
<tr>
	<td colspan="2" align="left">
		    <h:inputHidden id="contentType" value="#{viewSectionsPage.section.contentType}"/>
			 <h:inputHidden id="openWindow" value="#{viewSectionsPage.section.openWindow}"/>
			
		<br> 
      
	 <h:outputLink id="viewSectionLink"  value="#{viewSectionsPage.contentLink}"  rendered="#{((viewSectionsPage.section.contentType == viewSectionsPage.typeLink ||
             viewSectionsPage.section.contentType == viewSectionsPage.typeUpload ||
             viewSectionsPage.section.contentType == viewSectionsPage.typeLTI ||
             viewSectionsPage.section.contentType == viewSectionsPage.typeResLink)&&
             (viewSectionsPage.contentLink != viewSectionsPage.nullString)&&
             (viewSectionsPage.section.openWindow == true))}" onclick="popup('http://localhost:8080/access/meleteDocs/content/private/meleteDocs/41ee14cf-5830-4d6b-a7a9-62fd98465f26/uploads/CreateAndAnalyzeTraceFiles.pdf')">
      <h:outputText id="sectitleLink" 
                           value="#{viewSectionsPage.linkName}">
      </h:outputText>
    </h:outputLink>
    <h:outputText id="contentFrame" value="<iframe id=\"iframe1\" src=\"#{viewSectionsPage.content}\" style=\"visibility:visible\" scrolling= \"auto\" width=\"100%\" height=\"700\"
    border=\"0\" frameborder= \"0\"></iframe>" rendered="#{((viewSectionsPage.section.contentType ==viewSectionsPage.typeLink)&&(viewSectionsPage.linkName !=
    viewSectionsPage.nullString)&&(viewSectionsPage.section.openWindow == false))}" escape="false" />

   <h:outputText value="#{viewSectionsPage.content}" escape="false" rendered="#{((viewSectionsPage.section.contentType == viewSectionsPage.typeEditor)&&(viewSectionsPage.content != viewSectionsPage.nullString))}"/>

	<h:outputText id="contentUploadFrame" value="<iframe id=\"iframe2\" src=\"#{viewSectionsPage.contentLink}\" style=\"visibility:visible\" scrolling= \"auto\" width=\"100%\" height=\"700\"
    border=\"0\" frameborder= \"0\"></iframe>" rendered="#{((viewSectionsPage.section.contentType == viewSectionsPage.typeUpload)&&(viewSectionsPage.section.openWindow == false))}" escape="false" />

	 <h:outputLink id="contentResourceLink"  value="#{viewSectionsPage.contentLink}" target="_blank"
                   rendered="#{((viewSectionsPage.section.contentType == viewSectionsPage.typeResLink)&&(viewSectionsPage.section.openWindow == false))}" >
      <h:outputText id="contentResourceLinkName"
                           value="#{viewSectionsPage.linkName}">
      </h:outputText>
    </h:outputLink>

	<h:outputText id="contentLTI" value="#{viewSectionsPage.contentLTI}"
              rendered="#{((viewSectionsPage.section.contentType == viewSectionsPage.typeLTI)&&(viewSectionsPage.section.openWindow == false))}" escape="false" />
	</td>
	</tr>


 <tr>
<td colspan="2" align="left"> &nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center">
					<f:subview id="bottommod">
						<jsp:include page="view_navigate.jsp"/>
					</f:subview>
</td>
</tr>
</table>
</td>
</tr>
<tr><td>
<table width="100%" height="20" border="0" cellpadding="3" cellspacing="0" >
   	<tr>
	 <td align="center" class="meleteLicenseMsg center"><B>
  			<jsp:include page="license_info.jsp"/>      
         </B></td></tr>
	    </table>
</td></tr>
</table>
</h:form>
</body>
</f:view>
</html>

The red colored code is the link for the new page....

Regards
Bhanu.

Dani AI

Generated

— short answer: capture the anchor's href in a click handler, send that value to your logging script, then open the link. 's "URL rewriting" idea is valid if you want every click to be routed through the server (guaranteed server-side logging even when JS is off), but for a dynamic client-side flow you can read the href and act immediately in JavaScript.

A simple, reliable client-side pattern:

  • attach a click handler to the anchor,
  • prevent default navigation,
  • send the target URL to your server (use navigator.sendBeacon or an image-ping as a fallback so the send won't block),
  • then open the URL (window.open or location.href) and focus the new window.

Example (adapt for your JSF outputLink by adding a class or onclick handler):

function handleClick(e) {
  e.preventDefault();
  var url = this.href || this.getAttribute('href');
  if (navigator.sendBeacon) {
    navigator.sendBeacon('/logClick', JSON.stringify({ url: url }));
  } else {
    var img = new Image();
    img.src = '/logClick?u=' + encodeURIComponent(url);
  }
  var opts = 'toolbar=no,location=no,menubar=no,width='+screen.width+',height='+screen.height+',top=0,left=0';
  var w = window.open(url, '_blank', opts);
  if (w) w.focus();
  return false;
}
document.querySelectorAll('a.loggingLink').forEach(function(a){ a.addEventListener('click', handleClick); });

Fullscreen caveat: you cannot programmatically "press F11". The correct API is the Fullscreen API (element.requestFullscreen()), and it must be called as part of a user gesture and usually on the same document/element. If the target page is same-origin you can request fullscreen on an iframe you control; if the target is cross-origin, have the target page request fullscreen itself (for user safety browsers typically block cross-window forcible fullscreen).

JSF notes: either set the rendered link to call the JS handler (onclick="return handleClick.call(this, event)") or use a server-side redirect endpoint (/logAndRedirect?target=...) if you prefer URL-rewriting/logging on the server. Test for popup blockers, same-origin restrictions, and always URL-encode the target when passing it to a logging endpoint.

use url rewriting ....to get usr form <a> tag

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.