-1

Below is a piece of code from "Cookie Consent" regarding a cookie banner with a link. Problem: The code opens the link in a new tab instead of the same tab/window - see bottom of code. What needs to be added/changed to make this work? Also window.open("https://www.youraddress.com","_self") doesn't seem to solve the problem. Edit2: Changing the "element" as suggested still doesn't produce the correct result...

    <link rel="stylesheet" type="text/css" 
 href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.js"></script>
<script>
window.addEventListener("load", function(){
window.cookieconsent.initialise({
  "palette": {
    "popup": {
      "background": "#ebebeb",
      "text": "#404040"
    },
    "button": {
      "background": "#ff0099",
      "text": "#ffffff"
    }
  },

  "elements": { 
  "link": '<a aria-label="learn more about cookies" tabindex="0" class="cc-link" href="{{href}}" target="_self">{{link}}</a>',
},
  "content": {
    "href": "https://www.example.com/privacy-policy" 
  }

})});
</script>
Alex
  • 125
  • 1
  • 2
  • 13
  • Possible duplicate of [Open URL in same window and in same tab](https://stackoverflow.com/questions/8454510/open-url-in-same-window-and-in-same-tab) – dimwittedanimal Jun 26 '18 at 12:37
  • 2
    Isn't it possible to give it a target self? – D.Sof Jun 26 '18 at 12:38
  • 1
    Check the [element](https://cookieconsent.insites.com/documentation/javascript-api/) section – trinaldi Jun 26 '18 at 12:43
  • @Tico could let me know where exactly the part is where to change the link target on the Cookie Consent site? – Alex Jun 26 '18 at 13:07
  • Found it... However, no clue what parts of the code in the "element" section I need to merge with the code provided above. – Alex Jun 26 '18 at 14:48

3 Answers3

1

To open a link in same tab in JavaScript , use the code :

window.open("https://www.youraddress.com","_self");
4b0
  • 21,981
  • 30
  • 95
  • 142
Gold Chess
  • 69
  • 2
0

To open a link in same tab in JavaScript , use the code :-

window.location = 'http://www.google.com' ;

Check this link Your Example to see this is working.

PHP Web
  • 257
  • 3
  • 8
0

Ok, here is the working code regarding "Cookieconsent" opening the "Learn more" link in the same window:

<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.js"></script>
<script>
window.addEventListener("load", function(){
window.cookieconsent.initialise({
  "palette": {
    "popup": {
      "background": "#ebebeb",
      "text": "#404040"
    },
    "button": {
      "background": "#ff0099",
      "text": "#ffffff"
    }
  },

  "elements": {
      'messagelink': '<span id="cookieconsent:desc" class="cc-message">\{\{message\}\} <a aria-label="learn more about cookies" tabindex="0" class="cc-link" href="\{\{href\}\}" target="_self">\{\{link\}\}</a></span>',
      'link': '<a aria-label="learn more about cookies" tabindex="0" class="cc-link" href="\{\{href\}\}" target="_self">\{\{link\}\}</a>'
                        },
  "content": {
    "href": "https://www.example.com/learn-more" 
  }

})});
</script>
Alex
  • 125
  • 1
  • 2
  • 13