Can we get community base url without apex?
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-aura-components community
add a comment |
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-aura-components community
add a comment |
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-aura-components community
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-aura-components community
lightning-aura-components community
asked Nov 14 '18 at 16:37
sfdcLynxsfdcLynx
1356
1356
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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 '18 at 16:45
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "459"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 '18 at 16:45
add a comment |
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 '18 at 16:45
add a comment |
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 '18 at 16:59
sfdcLynx
1356
1356
answered Nov 14 '18 at 16:43
LetMeCodeYouLetMeCodeYou
525310
525310
1
use document.location instead of window.location since this has issues in Microsoft browsers.
– RedDevil
Nov 14 '18 at 16:45
add a comment |
1
use document.location instead of window.location since this has issues in Microsoft browsers.
– RedDevil
Nov 14 '18 at 16:45
1
1
use document.location instead of window.location since this has issues in Microsoft browsers.
– RedDevil
Nov 14 '18 at 16:45
use document.location instead of window.location since this has issues in Microsoft browsers.
– RedDevil
Nov 14 '18 at 16:45
add a comment |
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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