Custom code seemingly not working

Hi,
I’m trying to make the below custom code work but unfortunately with no success.
It’s to disable scrolling when a modal is visible.
The Safari inspector says that the variable Webflow can’t be found, I suspect that that might be the issue?

This is the project : https://preview.webflow.com/preview/retablo-feudi-castellazzo?utm_medium=preview_link&utm_source=dashboard&utm_content=retablo-feudi-castellazzo&preview=920cc9e979ba3f4fc03f5ef0e7f40301&mode=preview

<script>
Webflow.push(function() {
$('.MenuOpen_Button').click(function(e) {
e.preventDefault();
$('body').css('overflow', 'hidden');
 });

$('.MenuClose_Button').click(function(e) {
e.preventDefault();
$('body').css('overflow', 'auto');
});
});
</script>

I can see Webflow (and its push function) exists as a property on your page’s window object.

Are you missing the opening <script> tag in your code?

Also, you might need to change the first line to window.Webflow.push(function() {

Hi thanks for taking a look.
I did add ‘window.’ but that made no difference.
The opening tag was already there.
Weird, as this is simple jQuery code and people seem to have used it successfully but not me…

Code that depends on jQuery has to be loaded before the body close tag. Not in the document head.

1 Like

Hi even I am having problems with custom code, i posted here, but no one sees it or replies ;-;

As @webdev suggested, try moving your code just before the </body> tag and it should work!

@GoatPlayz_Fortnite I can now see you’ve had a response to your post.

Thank you guys, makes total sense, will give this a try shortly and possibly mark as solution.

1 Like