Join the Webstudio community

Updated 10 months ago

Javascript functions for element content

At a glance

The community member is looking to create a custom JavaScript function with parameters that can be used in an Expression to set content dynamically. The main use case is for building a landing page for Google Ads, where the community member wants to capture query string details and use complex logic to customize the headline, paragraph, and even the hero image based on the ad and keyword information.

In the comments, another community member asks if the requirement is for server-side rendering or only in browser scripts, and the original poster responds that either would be fine, as the main goal is to make the landing page feel highly relevant to the user who clicked on the ad.

This would be highly valuable to me.
Right now, it's possible to set content via a Javascript Ternary in Expression. I'd like to be able to have a custom JS fuction with param(s) and call that in the Expression to set the content.
I can imagine many uses cases but the most immediate for me is being able to have complex logic based on the query string.
Specifically, I'm building a landing page for Google Ads. Google rewards landing pages that are highly relevant to the ad and the keyword. Google allows us to pass as query string details about the ad and keyword.
I want to capture the query strings and run through a series of If and/o switch blocks so I can customize the headline and initial paragraph. Maybe even the hero image.
The logic would need much more than simple ternary.
B
H
2 comments
Do you need it for server side rendering or only in browser scripts?
I think either one would be fine. The main goal is for the user to instantly feel the LP is exactly what they were looking for when they clicked on the ad. I don't think there needs to be an SEO or crawler-capable version.
Add a reply
Sign up and join the conversation on Discord