Can we get community base url without apex?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}
up vote
4
down vote
favorite
I want to get community base url in my lightning component without apex. Right now I am using the design component to store the value but that is not optimal as I have multiple page references and typing each of them in the community builder is really hard and error prone.
lightning-components community
New contributor
add a comment |
up vote
4
down vote
favorite
I want to get community base url in my lightning component without apex. Right now I am using the design component to store the value but that is not optimal as I have multiple page references and typing each of them in the community builder is really hard and error prone.
lightning-components community
New contributor
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I want to get community base url in my lightning component without apex. Right now I am using the design component to store the value but that is not optimal as I have multiple page references and typing each of them in the community builder is really hard and error prone.
lightning-components community
New contributor
I want to get community base url in my lightning component without apex. Right now I am using the design component to store the value but that is not optimal as I have multiple page references and typing each of them in the community builder is really hard and error prone.
lightning-components community
lightning-components community
New contributor
New contributor
New contributor
asked Nov 14 at 16:37
sfdcLynx
1006
1006
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
5
down vote
accepted
Yes, you can retrieve the current page url in your JavaScript controller. And set the value of attribute in your component for later use according to your requirement.
Component
<aura:attribute name="cbaseURL" type="String"/>
JS Controller
var urlString = window.location.href;
var baseURL = urlString.substring(0, urlString.indexOf("/s"));
component.set("v.cbaseURL", baseURL);
Hope this helps.
EDIT:
As RedDevil highlighted that using window.location can create issues with Microsoft browsers. I tend to search a bit and find out interesting result. So I'd like to all the readers must go through this stackoverflow link to read about the details and use whatever suits you best.
However the widely accepted answer says:
document.location is a synonym for window.location that has been
deprecated for almost as long as JavaScript has existed. Don't use it.
location is a structured object, with properties corresponding to the
parts of the URL. location.href is the whole URL in a single string.
Assigning a string to either is defined to cause the same kind of
navigation, so take your pick.
I consider writing to location.href = something to be marginally
better as it's slightly more explicit about what it's doing. You
generally want to avoid just location = something as it looks
misleadingly like a variable assignment. window.location = something
is fine though.
1
use document.location instead of window.location since this has issues in Microsoft browsers.
– RedDevil
Nov 14 at 16:45
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
Yes, you can retrieve the current page url in your JavaScript controller. And set the value of attribute in your component for later use according to your requirement.
Component
<aura:attribute name="cbaseURL" type="String"/>
JS Controller
var urlString = window.location.href;
var baseURL = urlString.substring(0, urlString.indexOf("/s"));
component.set("v.cbaseURL", baseURL);
Hope this helps.
EDIT:
As RedDevil highlighted that using window.location can create issues with Microsoft browsers. I tend to search a bit and find out interesting result. So I'd like to all the readers must go through this stackoverflow link to read about the details and use whatever suits you best.
However the widely accepted answer says:
document.location is a synonym for window.location that has been
deprecated for almost as long as JavaScript has existed. Don't use it.
location is a structured object, with properties corresponding to the
parts of the URL. location.href is the whole URL in a single string.
Assigning a string to either is defined to cause the same kind of
navigation, so take your pick.
I consider writing to location.href = something to be marginally
better as it's slightly more explicit about what it's doing. You
generally want to avoid just location = something as it looks
misleadingly like a variable assignment. window.location = something
is fine though.
1
use document.location instead of window.location since this has issues in Microsoft browsers.
– RedDevil
Nov 14 at 16:45
add a comment |
up vote
5
down vote
accepted
Yes, you can retrieve the current page url in your JavaScript controller. And set the value of attribute in your component for later use according to your requirement.
Component
<aura:attribute name="cbaseURL" type="String"/>
JS Controller
var urlString = window.location.href;
var baseURL = urlString.substring(0, urlString.indexOf("/s"));
component.set("v.cbaseURL", baseURL);
Hope this helps.
EDIT:
As RedDevil highlighted that using window.location can create issues with Microsoft browsers. I tend to search a bit and find out interesting result. So I'd like to all the readers must go through this stackoverflow link to read about the details and use whatever suits you best.
However the widely accepted answer says:
document.location is a synonym for window.location that has been
deprecated for almost as long as JavaScript has existed. Don't use it.
location is a structured object, with properties corresponding to the
parts of the URL. location.href is the whole URL in a single string.
Assigning a string to either is defined to cause the same kind of
navigation, so take your pick.
I consider writing to location.href = something to be marginally
better as it's slightly more explicit about what it's doing. You
generally want to avoid just location = something as it looks
misleadingly like a variable assignment. window.location = something
is fine though.
1
use document.location instead of window.location since this has issues in Microsoft browsers.
– RedDevil
Nov 14 at 16:45
add a comment |
up vote
5
down vote
accepted
up vote
5
down vote
accepted
Yes, you can retrieve the current page url in your JavaScript controller. And set the value of attribute in your component for later use according to your requirement.
Component
<aura:attribute name="cbaseURL" type="String"/>
JS Controller
var urlString = window.location.href;
var baseURL = urlString.substring(0, urlString.indexOf("/s"));
component.set("v.cbaseURL", baseURL);
Hope this helps.
EDIT:
As RedDevil highlighted that using window.location can create issues with Microsoft browsers. I tend to search a bit and find out interesting result. So I'd like to all the readers must go through this stackoverflow link to read about the details and use whatever suits you best.
However the widely accepted answer says:
document.location is a synonym for window.location that has been
deprecated for almost as long as JavaScript has existed. Don't use it.
location is a structured object, with properties corresponding to the
parts of the URL. location.href is the whole URL in a single string.
Assigning a string to either is defined to cause the same kind of
navigation, so take your pick.
I consider writing to location.href = something to be marginally
better as it's slightly more explicit about what it's doing. You
generally want to avoid just location = something as it looks
misleadingly like a variable assignment. window.location = something
is fine though.
Yes, you can retrieve the current page url in your JavaScript controller. And set the value of attribute in your component for later use according to your requirement.
Component
<aura:attribute name="cbaseURL" type="String"/>
JS Controller
var urlString = window.location.href;
var baseURL = urlString.substring(0, urlString.indexOf("/s"));
component.set("v.cbaseURL", baseURL);
Hope this helps.
EDIT:
As RedDevil highlighted that using window.location can create issues with Microsoft browsers. I tend to search a bit and find out interesting result. So I'd like to all the readers must go through this stackoverflow link to read about the details and use whatever suits you best.
However the widely accepted answer says:
document.location is a synonym for window.location that has been
deprecated for almost as long as JavaScript has existed. Don't use it.
location is a structured object, with properties corresponding to the
parts of the URL. location.href is the whole URL in a single string.
Assigning a string to either is defined to cause the same kind of
navigation, so take your pick.
I consider writing to location.href = something to be marginally
better as it's slightly more explicit about what it's doing. You
generally want to avoid just location = something as it looks
misleadingly like a variable assignment. window.location = something
is fine though.
edited Nov 14 at 16:59
sfdcLynx
1006
1006
answered Nov 14 at 16:43
LetMeCodeYou
51838
51838
1
use document.location instead of window.location since this has issues in Microsoft browsers.
– RedDevil
Nov 14 at 16:45
add a comment |
1
use document.location instead of window.location since this has issues in Microsoft browsers.
– RedDevil
Nov 14 at 16:45
1
1
use document.location instead of window.location since this has issues in Microsoft browsers.
– RedDevil
Nov 14 at 16:45
use document.location instead of window.location since this has issues in Microsoft browsers.
– RedDevil
Nov 14 at 16:45
add a comment |
sfdcLynx is a new contributor. Be nice, and check out our Code of Conduct.
sfdcLynx is a new contributor. Be nice, and check out our Code of Conduct.
sfdcLynx is a new contributor. Be nice, and check out our Code of Conduct.
sfdcLynx is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f239372%2fcan-we-get-community-base-url-without-apex%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown