Skip to main content
Answer

Remove Typeform-generated content when moving between pages

  • December 28, 2021
  • 9 replies
  • 143 views

Hello!

We have an SPA where we’re showing a Typeform questionnaire on the home/dashboard page, but we then want to remove the Typeform on navigating to a different page.  Typeform generates its own HTML to present the questionnaire:

Is there a consistent way that we can use to access this content (something that will be consistent from version to version)?  Previously we were using the “typeform-sidetab” class to find it, but now this has changed to “tf-v1-sidetab”, and it might change again in future…  Is there a way that we can ID the Typeform-generated div ourselves perhaps?  Or is there some clean-up function we can invoke if we want to remove the Typeform HTML when navigating to a different route?

Best answer by mathio-tf

Hello @stahfacedquail 

if you have a SPA then you can render your typeform sidetab only on pages you want to display it on.

If you want a hacky solution you can use the “tf-v1-sidetab” class name for now or wrap the embed code in a custom element and hide that one.

9 replies

Liz
Ex–Typefomer
Forum|alt.badge.img+5
  • Tech Community Advocate
  • December 28, 2021

Hi @stahfacedquail Happy Tuesday! Thanks for stopping by the community. This would definitely involved some custom-coding, so I’m tagging @mathio here who may already have a solution for you. :grinning:


mathio-tf
Typeform
Forum|alt.badge.img+5
  • Typeform
  • Answer
  • December 28, 2021

Hello @stahfacedquail 

if you have a SPA then you can render your typeform sidetab only on pages you want to display it on.

If you want a hacky solution you can use the “tf-v1-sidetab” class name for now or wrap the embed code in a custom element and hide that one.


  • Author
  • Explorer
  • December 28, 2021

Thanks so much, @Liz and @mathio ; this definitely helps.  The idea of embedding the code in a custom element sounds like it would work best for us as we want to avoid duplicating the Typeform code…  How can we direct Typeform to put the code into a specific element?  I would have thought the “container” option would help, but I see that only works for the widget?


mathio-tf
Typeform
Forum|alt.badge.img+5
  • Typeform
  • December 28, 2021

You can try something like this:

<div id="my-typeform-container">
<!-- place you embed snippet here -->
</div>

Then you can use CSS or JavaScript to show & hide the my-typeform-container element.


  • Author
  • Explorer
  • December 28, 2021

Thanks, @mathio ; I’ve now targetted a specific div for the embed and it’s working like a charm.  I just want to double-check: am I correct in saying that one can only specify where to do the embed if they embed via JS?  There isn’t a way to direct the embed if embedding via HTML (and that Typeform will always default to appending the form to the document’s body element in this case)?


mathio-tf
Typeform
Forum|alt.badge.img+5
  • Typeform
  • December 29, 2021

You can do it via both HTML and JS embed codes. It all depends on how you build your website.


  • Author
  • Explorer
  • December 30, 2021

In the HTML embed case, does the location of the embed depend on where I put the div with all the data-tf-… attributes, or can I specify the container for the embed by using an attribute something like below:

data-tf-container=”div#theEmbedContainer”

 


mathio-tf
Typeform
Forum|alt.badge.img+5
  • Typeform
  • December 30, 2021

Sorry, you are correct, you need to use JS embed to place the embed into a specific div.

To use HTML snippet you would need to conditionally include the snippet in your SPA.


  • Author
  • Explorer
  • December 30, 2021

Perfect; thanks for all your help!  Thanks so much.