Hi
When an image is clicked, I want to open two new windows: first at the same window and the second as a new tab (opening as 2 new windows is also fine).
What I did is:
$w.onReady( function () {
$w('#image1').link = "***";
$w('#image1').target = "_blank";
});
export function image1_click(event) {
wixLocation.to (“***”);
}
It works but I don’t feel comfortable with it, and I’m not sure it always work. Is there another idea?
I also thought to open a new window and use Router to open another window on loaded, but you can’t use wixLocation on backend.
You can do it this way:
import wixLocation from ‘wix-location’;
$w.onReady( function () {
$w('#image1').link = "https://www.google.com";
$w('#image1').target = "_blank";
});
export function image1_click_1(event) {
//Add your code for this event here:
wixLocation.to(“http://yahoo.com ”);
$w(‘#image1 ’).target = “_blank”;
}
You will get first link opening in a new tab and second (onClick fn) will open the link in the same tab.
J.D
October 29, 2019, 2:07pm
3
The second .target is not necessary and I think it does nothing. Am I wrong?
@jonatandor35 Think you are right as the code would have moved the user onto Yahoo page already.
J.D
October 30, 2019, 10:06am
5
@givemeawhisky and anyway the link is already set to “_blank”. No need to set it again.