0

I've got a variable that gets the server url of the user:

var server = parent.Xrm.Page.content.getClientUrl;

I want to use that variable to be the first part of a html link and add the page name to the end of it to generate links for different pages. For example for the home page I need the a href to be a combination of var server and /homepage. I tried the following:

<a href="" onclick="this.href = 'server'+'/homepage" target="_blank">

But this didn't work. Any solution would be appreciated!

2
  • stackoverflow.com/a/19550497/4903314 Commented Nov 11, 2019 at 9:39
  • @UmairKhan I don't need to get the website url.. I already have that. I need to set it as a variable alongside and text. Commented Nov 11, 2019 at 9:40

1 Answer 1

1

You can write an onclick method which will be implemented in javascript. There you will get the variable.

HTML:

<a href="" onclick="getUrl()" >

JS:

getUrl(){
window.open(server +'/homepage,  '_blank');
}

or you can send the extra string from html as parameter

<a href="" onclick="getUrl('/homepage')">

-

getUrl(url){
window.open(server + url,  '_blank')

}
Sign up to request clarification or add additional context in comments.

1 Comment

The OPs <a> element has the target attribute set to _blank which will open the link in a new window/tab, window.location = .. will open the link in the current window/tab.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.