Re: Thank You URL to use as a javascript variable

Nicole_Van
Level 1

Thank You URL to use as a javascript variable

Has anyone had success in using the thank you page URL of a Marketo form as a javascript variable?

 

I want to be able to reference the thank you page based off of the form that lives on the landing page, but I'm struggling to figure out how that would work.

 

For example, the browser URL could be pulled with window.location.href; is there a thank you page equivalent?

 

Looking for something similar to Sanford's thank you page redirect, but instead of a redirect, I just want to pull the link as a variable:

MktoForms2.whenReady(function(form) {   
  form.onSuccess(function(vals, tyURL) {
    var tyLoc = document.createElement("a");
    tyLoc.href = tyURL;
    tyLoc.search += "&fromURL=" + encodeURIComponent(document.location.href);      
    document.location = tyLoc;
    return false;
  });
});

 

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Thank You URL to use as a javascript variable

Well, the variable tyURL is a JS variable in that example? So not clear what you're asking.

Nicole_Van
Level 1

Re: Thank You URL to use as a javascript variable

Thanks Sanford! To clarify, I want it to return as a string.

 

e.g. if i type console.log(window.location.href);, it returns the browser URL

 

Is it possible to define the ty page URL as a text string so that I can plug it into a variable to use in a different script? Hope that makes sense.

SanfordWhiteman
Level 10 - Community Moderator

Re: Thank You URL to use as a javascript variable

It is a String variable!

 

It's not a global variable, but setting a global (window) variable isn't a good idea because you can't use it until it's ready in any case. You might declare a global function and then pass tyURL into it:

function doSomethingWithThankYou(vals, tyURL){
  // do whatever with tyURL
  return false;
}

MktoForms2.whenReady(function(form) {   
  form.onSuccess(doSomethingWithThankYou);
});