Writing a cookie before redirect to an external site that is not AEM | Community
Skip to main content
Level 6
April 19, 2023

Writing a cookie before redirect to an external site that is not AEM

  • April 19, 2023
  • 2 replies
  • 655 views

Hi

I need to write a cookie before redirecting to an external site that is not AEM. The redirect site is a normal link. What is the recommended approach to do that?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

ShaileshBassi
Community Advisor
Community Advisor
April 19, 2023

Hi @anasustic Use can use the below javascript section for adding the cookie.

 

$(function() { $(document).on( "click", "a" function() { var currentElement = $(this); var url = $(this).attr("href"); if(!link_is_internal(url)) { document.cookie = 'cookie-value'; // setting a new value } }); function link_is_internal(url) { return (url.indexOf(window.location.host) !== -1 || url.startsWith("/")); } });

 

 link_is_internal method over here is handing both the absolute url and the internal link over here, before returning the result.

Hope this helps!

Thanks

anasusticAuthor
Level 6
April 20, 2023

Thank you very much @shaileshbassi