cancel
Showing results for 
Search instead for 
Did you mean: 

URL of the current portal page loaded using Javascript ?

Former Member
0 Kudos

Hello:

I am trying to add programmatically the url of the current

page loaded in the portal to the 'Favorites List'. There

is a pre-built KM iview to store your 'favorites'.

I can extract and write to this 'favorites' using KM java

API. But only challenge is to extract the current loaded

page URL and title using Javascript.

I would appreciate any help in this regard.

Thank you very much,

Prasad Nutalapati

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

or if the breadcrumb is not available, or you want to do it on the serverside instead of javascript, you can use the NavigationEventsHelperService to get the launchurl (of the page) after the POM node is loaded.

I'll send you an email with an example.

Former Member
0 Kudos

What jar file i must import for use NavigationEventsHelperService?

Florin

Former Member
0 Kudos

I got this class from Mr.Ron Hendrickx of SAP America.

You will implement this method as part of your AbstractPortalComponent class.

protected void doOnNodeReady(

IPortalComponentRequest request,IEvent arg1) {

//super.doOnNodeReady(request, arg1);

NavigationEventsHelperService helperService =

(NavigationEventsHelperService) PortalRuntime

.getRuntimeResources()

.getService("com.sap.portal.navigation.helperservice.navigation_events_helper");

navTargetNode = helperService.getCurrentLaunchNavNode(request);

request.getNode().putValue("navNode", navTargetNode);

}

The imports are ...

import com.sapportals.portal.navigation.INavigationNode;

import com.sapportals.portal.navigation.NavigationEventsHelperService;

import com.sapportals.portal.prt.component.AbstractPortalComponent;

import com.sapportals.portal.prt.component.IPortalComponentRequest;

import com.sapportals.portal.prt.component.IPortalComponentResponse;

import com.sapportals.portal.prt.pom.IEvent;

import com.sapportals.portal.prt.runtime.PortalRuntime;

The jar files are..

com.sap.portal.navigation.helperserviceapi.jar

com.sap.portal.navigation.serviceapi.jar

This is one of the approaches (with Java). As suggested

by others, youcan use Javascript also to achieve this.

Hope this helps,

Prasad Nutalapati

Answers (3)

Answers (3)

Former Member
0 Kudos

Dude i was having the exact same problem. I solved it using the SAP-provided EPCM (javascript client framework).

/*********************

  • Javascript Code

*

********************/

var pageName = "";

var URL = "";

function bookmarkPage()

{

/* page url */

var fullURL = "https://<%=request.getServerName()%>/irj/portal?NavigationTarget=" + URL;

/* IE bookmark */

if(EPCM.getUAType() == EPCM.MSIE)

{

window.external.AddFavorite(fullURL , pageName);

}

else

{

var msg = "Sorry. The \"Add To Favorites\" feature only works with Internet Explorer. " +

"The URL to this page is " + fullURL;

alert(msg);

}

}

/* get pagename from eventObject from subscribed event */

function getPageObject(eventObj) {

pageName = eventObj.dataObject.title;

URL = eventObj.dataObject.URL;

}

/* subscribe to event in pagetoolbar area */

EPCM.subscribeEvent("urn:com.sapportals:navigation", "AddNavTargetAllowDuplicate", getPageObject);

/*****************

  • End of code

*

****************/

Basically, what this does is that everytime a page loads, the innerpage, where the content is, raises an event using the EPCM.raiseEvent() method. EPCM.subscribeEvent subscribes to an event called AddNavTargetAllowDuplicate which has an object holding the page information (i.e. page title and URL (ROLE://...)). Everytime that it notices an event raised, the function getPageObject gets called to go get data from the event object that is available globally in the framework.

You should be able to put this code anywhere in any iview and it should work. Thou i have only tried putting it in the masthead. Try and if you still have questions please let me know.

Former Member
0 Kudos

Hi,

I you are having the standard BreadCrumb in your Portal Desktop, then you can use various methods/variables available in the HistoryFramwork.js

For example to simply find the URL, Title of the current loaded Page you can use, the following code snippet in your iView.

index = top.gHistoryFrameworkObj.GetActiveTrackingEntryIndex();

name = top.gHistoryFrameworkObj.TrackingEntries.TrackingStackContainer[index].title

url = top.gHistoryFrameworkObj.TrackingEntries.TrackingStackContainer[index].URL

Hope this helps.

Thanks

Ankur

Former Member
0 Kudos

For the current page url you can use window.location

The title is alot more difficult. Perhaps you can do it with a javascript DOM browser (http://javascript.internet.com/page-details/dom-browser.html) by searching for the <title> element in the source.