Redirect back to Discourse Topic From Another Domain


(Ivan) #1

Hi there,

What I’m trying to do is redirect a non-signed in user back to Discourse after being sent off to our Wordpress domain to signup. Some logic on the WP home page was to check whether or not a cookie with the name ‘redirectTo’ was present, and if it was, redirect them back to the topic (value of the cookie) that the user had attempted to click ‘Like’ on.

As you can see from the JS code I have so far in Discourse, a cookie is assigned to the user when they click on the ‘Like’ button, but alas since the WP domain (randomwebsite) is not the same as our Discourse (ask.randomwebsite), the cookie doesn’t travel to WP.

JS code in Discourse so far:

    $(document).ready(function(){
      $('body').on('click', '.custom-like, .like', function() {
        var url = window.location.href;
        var d = new Date(); 
        d.setMinutes(d.getMinutes() + 30);
        var expires = "expires="+ d.toUTCString();
        document.cookie = "directTo=" + url + "; " + expires;

        if(Discourse.User.current()){
         //Stay on the page
        } else {
          location.href = 'https://randomwebsite.com/join/?try=comment';
        }
      });
    });

Do you guys have any suggestions as to what could be done?

Thanks!

Edit: Didn’t realize document.referrer was a thing. Will investigate further with this.


(Dean Taylor) #2

Consider checking out the mentions of both iframe and embed in this post: