1 Reply Latest reply on Aug 8, 2019 8:07 AM by Daniel Merchán

    Webcenter 12c- calling javascript on page load while navigating between webcenter pages

    4038815

      Hi all,

       

      We are working with Web-center 12c(12.2.1.3) and facing an issue stated below.

       

      Approach:

      We have a custom navigation model  between the pages at web-center level and we are not redirecting to other pages

       

      Problem:

       

      Problem is we need to capture page load for analytics to the check number of triggers on website and we are facing problem in calling JavaScript while navigating between pages.

      window.ready() / window.onload() is not getting called during page navigation as for pages redirection are unchecked and method gets only called if direct URL hit or page is refreshed.

      Please help me with some approach how we can achieve this?

      How can we get the JavaScript executed at the time of page navigation at web-center level?

        • 1. Re: Webcenter 12c- calling javascript on page load while navigating between webcenter pages
          Daniel Merchán

          Hi,

           

          So I assume you are doing PPR navigation with an af:link or af:button. Can you paste the snippet of code on how are you navigating?

           

          The are multiple choices. One is the following:

           

          • Edit the WebCenter Portal Pages you already created (Page Source via Admin Console) for adding your javascript like the following snippet of code:

          <af:document id="d1">       
          ...
             <af:clientListener method="onPageLoad" type="load">
               <af:clientAttribute name="pageTitle" value="#{pageDocBean.title}"/>
               <af:clientAttribute name="pagePath" value="#{pageDocBean.pagePath}"/>
               <af:clientAttribute name="pageName" value="#{pageDocBean.pageName}"/>
               <af:clientAttribute name="userId" value="#{securityContext.userName}"/>
             </af:clientListener>
             <f:facet name="metaContainer"> 
               <af:resource type="javascript"> 
                  function onPageLoad(evt) {             
                      var pageTitle = evt.getSource().getProperty('pageTitle');
                      var pagePath = evt.getSource().getProperty('pagePath');
                      var pageName = evt.getSource().getProperty('pageName');
                      var userId = evt.getSource().getProperty('userId');
          // Your Google Analytics code
                  }             
               </af:resource>       
             </f:facet>     
          </af:document>
          
          

           

          • You can create your own Page Styles based on your WCP Pages which already includes already your JavaScript code above and the load event (so you do not have to go page by page you create to add your snippet).

           

          Kind regards.