Planned maintenance is scheduled for the week of June 15th - the exact date and time will be announced soon.
See More Details
Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Replace href dynamically using Javascript
Hello,
I want to replace all href dynamically using Javascript when the page is loaded, because I need to use the class Liferay.PortletURL and it has a problem when the session is timeout. So I thought that I can replace this value with the url.
This piece of code doesn't works:
But when I run using the console of firebug, the href were replaced without problem.
Any idea? Thanks
Jonatan
I want to replace all href dynamically using Javascript when the page is loaded, because I need to use the class Liferay.PortletURL and it has a problem when the session is timeout. So I thought that I can replace this value with the url.
This piece of code doesn't works:
AUI().ready(
/*
This function gets loaded when all the HTML, not including the portlets, is
loaded.
*/
function() {
Liferay.provide(
window,
'showEjercicio',
function(articleId, title) {
var url = Liferay.PortletURL.createRenderURL();
url.setWindowState('maximized');
url.setPortletId("9_WAR_magnapediaportlet");
url.setParameter("articleId", articleId);
url.setParameter("title", title);
return url.toString();
},
['liferay-portlet-url']
);
AUI().all("a").each
(
function(node)
{
if(node.attr("href").indexOf("showEjercicio") > -1)
{
var fstr = decodeURI(node.attr("href"));
fstr = fstr.replace("javascript", "");
fstr = fstr.replace("showEjercicio", "");
fstr = fstr.replace(":", "");
fstr = fstr.replace(";", "");
fstr = fstr.replace("(", "");
fstr = fstr.replace(")", "");
fstr = fstr.replace(/'/g, "");
fstr = fstr.replace(/ /g, "");
var args = fstr.split(",", 2);
var url = window["showEjercicio"].apply(this, args);
if(url)
{
node.attr("href", url.toString());
}
}
}
);
}
);
But when I run using the console of firebug, the href were replaced without problem.
AUI().all("a").each
(
function(node)
{
if(node.attr("href").indexOf("showEjercicio") > -1)
{
var fstr = decodeURI(node.attr("href"));
fstr = fstr.replace("javascript", "");
fstr = fstr.replace("showEjercicio", "");
fstr = fstr.replace(":", "");
fstr = fstr.replace(";", "");
fstr = fstr.replace("(", "");
fstr = fstr.replace(")", "");
fstr = fstr.replace(/'/g, "");
fstr = fstr.replace(/ /g, "");
var args = fstr.split(",", 2);
var url = window["showEjercicio"].apply(this, args);
if(url)
{
node.attr("href", url.toString());
}
}
}
);
Any idea? Thanks
Jonatan
Hi jonatan
Try to run your script on the allPortletsReady event instead of AUI().ready
The code should be :
Best Regards
Try to run your script on the allPortletsReady event instead of AUI().ready
The code should be :
Liferay.on('allPortletsReady',
function() {
AUI().all("a").each(function(node) {
if (node.attr("href").indexOf("showEjercicio") > -1) {
var fstr = decodeURI(node.attr("href"));
fstr = fstr.replace("javascript", "");
fstr = fstr.replace("showEjercicio", "");
fstr = fstr.replace(":", "");
fstr = fstr.replace(";", "");
fstr = fstr.replace("(", "");
fstr = fstr.replace(")", "");
fstr = fstr.replace(/'/g, "");
fstr = fstr.replace(/ /g, "");
var args = fstr.split(",", 2);
var url = window["showEjercicio"].apply(this, args);
if (url) {
node.attr("href", url.toString());
}
}
});
});Best Regards
Community
Company
Feedback