Please,
In a page of my site, I’m trying to use this simple 3-line javascript (working so fine in my old site), but I’m getting error messages:
var parametrounico= location.href.split(“?”); //here, only in wix, I’m getting the error “‘location’ is not defined”
var urlpadrao= “https://creator.zohopublic.com/accumakerapp/accumaker-anamnese/page-perma/Login/GPCj72GGD7NzwWKZN0kyanGtRrdX4pq411CWHEjejhnx6CpNR6baGQxSuRYe3OK3Aa4S4sXvnX7yHEW0Us01vPkXyCz8jFWHK28q”;
window.location.replace(urlpadrao+“?”+parametrounico[1]);//here, only in wix, I have the error “‘window’ is not defined”
Someone can help me please?
Thanks in advance,
Luciano
At wix, you cannot access location or window directly. You can use wixLocation and wixWindow given you import the modules.
And then, I am not sure what you are trying to do here, you may need to have a look at the other wix modules as well.
what I’m trying to do is:
For example, when user go to my site (in a page called index) through url:
www.accumaker.com/index?par1=par1valu e
This script must redirect him to:
www.externalurl.com?par1=par1value
These 3 lines were doing this task successfully, but in wix I’m getting the mentioned errors .
Could you help me on an example code I need to use?
As Yoav wrote, “location” and “window” aren’t accessible in wixcode. You need to use wixLocation.url instead of “location” and use wixLocation.to() instead of “window.location.replace”.
Don’t forget to add
import wixLocation from 'wix-location';
to the top of your file.
Well, i inputed this way above - the error messages has disappeared, but the redirection does not happend.
The code is above and the page is in https://accumakerapp1.wixsite.com/website-1/index.
import wixLocation from ‘wix-location’;
var parametrounico = wixLocation.url.href.split(“?”);
var urlpadrao = “https://creator.zohopublic.com/accumakerapp/accumaker-anamnese/page-perma/Login/GPCj72GGD7NzwWKZN0kyanGtRrdX4pq411CWHEjejhnx6CpNR6baGQxSuRYe3OK3Aa4S4sXvnX7yHEW0Us01vPkXyCz8jFWHK28q”;
wixLocation.to(urlpadrao + “?” + parametrounico + parametrounico[1]);
Please help me 
I tried even a more simple way, just to try the function:
import wixLocation from ‘wix-location’;
wixLocation.to(“http://wix.com”);
And even this way, no redirection happened.
@accumakerapp As Yoav and Ohad have stated you need to use the Wix APIs. They do not operate as standard javascript DOM APIs. Like JQuery has its own framework of functions so too does Wix.
You need to read the API documentation for wix-location here:
So your three lines of code would need to look like this:
import wixLocation from 'wix-location';
$w.onReady(() => {
var parametrounico = wixLocation.url.split("?");
var urlpadrao =
"https://creator.zohopublic.com/accumakerapp/accumaker-anamnese/page-perma/Login/GPCj72GGD7NzwWKZN0kyanGtRrdX4pq411CWHEjejhnx6CpNR6baGQxSuRYe3OK3Aa4S4sXvnX7yHEW0Us01vPkXyCz8jFWHK28q";
wixLocation.to(urlpadrao+"?"+parametrounico[1]);
});
Cheers
Steve
@stevendc now it worked fine!
thanks a lot !!
@accumakerapp Good to know. Please tag the post as top comment. This helps other users see that your problem was solved and what the answer was.
Cheers
Steve