Marko
Marko

Reputation: 91

Add custom javascript to wix

I am trying to add custom javascript to wix, but it doesnt work. I have tried almost all I found on google but it doesnt work.

<script type="text/javascript">
    window.parent.location.href = "https://url/track"
</script>

The script above needs to be loaded on every wix page, it contains redirection

I was wondering if this is possible in wix?

Upvotes: 2

Views: 13172

Answers (3)

Tomislav SUFLAJ
Tomislav SUFLAJ

Reputation: 52

Make sure you've enabled DEV mode and then open the script panel at the bottom of the page. First, you should import the module that contains the method you need. In your case, that would be wixLocation. Inside the onReady function, you should call winLocation.to method.

import wixLocation from 'wix-location';
$w.onReady(function () {
    wixLocation.to("http://some.new.location"))
});

Upvotes: 1

Adam Matan
Adam Matan

Reputation: 136351

The way to add custom code to each page in a Wix site is by adding Site code in the built-in IDE.

To access it, enable Dev mode at the top menu and click the Site tab at the editor.

Note that you can't access the DOM directly. However, Wix has a pretty rich API that may cover your needs.

enter image description here

Upvotes: 3

Sweet Chilly Philly
Sweet Chilly Philly

Reputation: 3219

looks like you need to use the wix location API: https://www.wix.com/corvid/reference/wix-location.html#to

From my limited knowledge of wix it seems like your implementation is just wrong for the problem you're trying to solve.

I had a quick read of this article which isn't too old: https://www.wix.com/corvid/forum/community-discussion/page-redirect and it seems like a better approach.

Upvotes: 1

Related Questions