Hello!
I would like to open a new page from the button´s properties.
In HTML code this will be like this: “window.open(element.urlPage, ‘_blank’);”, but I don´t know how to do ir in wix.
Thank you!
Hello!
I would like to open a new page from the button´s properties.
In HTML code this will be like this: “window.open(element.urlPage, ‘_blank’);”, but I don´t know how to do ir in wix.
Thank you!
Hi,
As a preface to my answer…
WixCode understands all of Javascript, except for anything that accesses the DOM.
This keeps the user from inadvertently “breaking” something. I myself tried to hack things from the code, from an iFrame, and in my dreams, but WixCode wasn’t having any of it.
Accessing document elements such as div, span, button, etc is off-limits. The way to access elements on the page is only through $w.
Now, with that in mind, what you need to do is to use wix-location . To navigate to a specific URL, use wix-location.to() . Here is an example how to navigate to an about page:
wixLocation.to("/about");
This should get you going in the right direction.
Have fun,
Yisrael
Thank you!!
It´s its open the new url in the same page, and y would like to open it in new tab. It´s possible?
Thank you!
Hi,
As far as I know, the options of opening in the same page, new window, new tab are browser settting and that there’s really no method to code opening a URL in a new tab/window. I believe that there was at one time a standards proposal regarding this issue but so far it has not been approved.
Oh well
I also need to open a link in a new window.
Using the element’s:
element.target=“_blank”;
would seem to be the answer for a button or image or other element.
I am using dynamically created links based upon a client clicking the email column in a table. I can use:
wixLocation.to(“mailto:” + customerEmail+ “?subject=Responding to your purchase order…”);
This works great. It opens the email client, pre-filled with email address and subject, but in the same window. This forces the client to reload the database (and password screens) after sending the email.
Can I set the target property of wixLocation somehow to “_blank”?
Hi Roger,
It is not possible to combine wixLocation.to with target=_blank.
First of all feel free to add a feature request here .
My suggestion is to use a repeater and design it like a table. In the email column add a button element with _blank as target.
Roi
Instead of:
$w("#myElement").link = "/about-me";
$w("#myElement").target = "_blank";
We can use this to open a new tab:
import wixLocation from 'wix-location';
let BaseUrl = wixLocation.baseUrl;
let myLink = "/about-me"
$w("#myElement").link = BaseUrl + myLink;
$w("#myElement").target = "_blank";
The secret is to use http: // or https: // the URL for Google Chrome to open in a new tab when we use it: .target = “_blank”
Sorry, but this doesn’t open the link in another browser tab either, or I don’t know what I’m doing wrong Can someone help me?
Here’s a workaround I made using HTML frames to open a URL in a new tab from velo:
https://youtu.be/7yp-kLGu1Yw