I’ve searched the forum and not found any solutions to this yet. Does anyone know how to have one page of my website re-direct or forward to an external web address?
For example, I want https://www.shapeofthesun.com /song to immediately forward to the Spotify web address of the song (this is for a musician website).
Thanks for any help!
Just have a blank page and write it into the page onReady function, something like this.
import wixLocation from 'wix-location';
$w.onReady( () => {
wixLocation.to("http://wix.com");
}
Or just add it to a element on the page and either use the Wix Editor settings to link it to an external website or use code to direct it to a external website.
export function song_onclick(event) {
wixLocation.to("http://wix.com");
}
// With the properties panel onClick event handler.
$w("#song").onClick( (event) => {
wixLocation.to("http://wix.com");
}
// With the onClick event handler written into the code.
Thanks for responding! I am super new to this and have no idea what I’m doing. Do I just do this in the Page Code section at the bottom of a particular page? I’m not even sure what onReady is or how to add an element. Thank you again!
Firstly I would suggest that you read about Wix Corvid if you are all completely new to this.
https://support.wix.com/en/corvid-by-wix/basics
https://www.wix.com/corvid/reference
As for the code itself, how are you looking at having the song on the page to redirect the user to the external song page?
Shown in previous reply, if you simply have a choice of songs on your page and you have a basic button underneath, then simply have the button setup to have the user directed to that page.
export function song_onclick(event) {
wixLocation.to("http://wix.com");
}
// With the properties panel onClick event handler.
See here for more info about working with event handlers etc.
Velo: Reacting to User Actions Using Events | Help Center | Wix.com
If you are wanting a to go to a certain page like Fastest Web Hosting Services | Buy High Quality Hosting automatically open a external page URL then do the other option in your page code.
Simply have a blank page so that there is nothing on it and then delete everything already in that page code panel and add this into it.
import wixLocation from 'wix-location';
$w.onReady( () => {
wixLocation.to("http://wix.com");
}
As there is nothing actually on that page, it should load very quick and go straight to that external URL link almost immediately.
Finally, if you have a lot of external links for a particular piece of music, then I would suggest you do similar to what they have done on your link page of https://www.shapeofthesun.com and have labelled buttons for each option which will direct them to the appropriate external URL when they are clicked on.
Thanks so much! I am currently reading the Basics and Reference that you linked. I am trying to do what you describe here “If you are wanting a to go to a certain page like www.yourwebsite.com/pagenameURL automatically open a external page URL then do the other option in your page code.”
When I input the code I get this error "public/pages/fzlrq.js: Unexpected token, expected , (5:1) "
For this part of the code that you gave me, should it literally say ‘wix-location’ in my code or do I need to edit that to my specific page? Thanks again!
import wixLocation from 'wix-location';
It works now! I think it was just a problem with the new page that I created (the URL name). THANK YOU SO MUCH!