My code is working in Preview but not on published site.

I have put a code and that is working properly in preview but is not working on Live website. Please anyone help.
My code:

import wixLocation from ‘wix-location’ ;

// Navigation
const nextPage = () => {
wixLocation . to ( “/home-1” );
};

$w . onReady ( function () {
const button = $w ( ‘#Enterbutton’ );
const focusTrap = $w ( ‘#input1’ );

button . onClick (() => {
nextPage ();
});

focusTrap . onKeyPress (( event ) => {
if ( event . key === ‘Enter’ ) {
nextPage ();
}
});

// Focus trap.
// If user click somewhere then we return the focus to input
focusTrap . onBlur (() => {
setTimeout (() => {
focusTrap . focus ();
}, 100 );
});

focusTrap . focus ();
});

Hi Saksham,

did you publish? :stuck_out_tongue:
i tried the code and it works fine.
Clikking button sends me to home (Be Sure home is really home-1)
Pressing enter in the text field also sended me to home
Trying to get out of the text field keeps focusing back on that field.

Hi Kristof,
I have published the website, still it is not working on live website. But it is properly working on Preview. I have tried all the things which I can, but nothing works. Please help me. Link of my website:

working on preview:

it is not working on live site.

@madaansaksham2809
What isn’t working?
if i press on the enter button it goes to the home-1 page
Pressing enter on the keyboard isn’t working since there is no textfield to focus…

Kind regards,
Kristof.

@volkaertskristof Pressing enter key is not working, it works in preview, I have focus on textfield which is present behind the the enter button. The enter key on keyboard is working in preview but is not working in published site.

@madaansaksham2809
Try to focus on the text field when the button is getting visible.
I think the issue might be because of loading speed.
Probably the preview loads faster then the live.
If the element isn’t loaded yet in the preview but already gets focus then there is nothing to focus.

So a work around might be to trigger the focus when the enter button is visible.