I have an app that makes an API call to return the Wikipedia link for a selected country. When you select the country, the app uses jQuery to change the href of the link to the relative country:
<a id="txtWiki" class="text-info" target="_blank"></a>
$('#txtWiki').attr('href', (result['data'][0]['wikipediaUrl']));
The link does change, however when I click on the link it is adding the link to the end of the current URL in the bar – for example if I wanted it to go to https://en.wikipedia.org/wiki/France, clicking the link will take me to localhost/myappname/en.wikipedia.org/wiki/France.
I am unsure why this is happening, I thought that adding the _blank target attribute would solve this but it is not. What am I missing here?
>Solution :
I believe your code isn’t functioning as intended due to the use of a relative URL instead of an absolute one. Please try the following modification:
$('#txtWiki').attr('href', 'https://' + result['data'][0]['wikipediaUrl']);