Target = _blank is not working

using the following code the url is opening in the same page insted in a new one
let urlpoint = “https://www.google.co.il/”;
$w(‘#button5’).target = “_blank”;// “_self”;// 28.11.2019
wixLocation.to(urlpoint); //28.11.2019

Hi,
There is a workaround, set the link panel of the button as follows:


And use Corvid to update the button’s link ( https://www.wix.com/corvid/reference/$w.LinkableMixin.html#link )

also not working, other workaround? plz :S

Hi,

It may be an old problem but I have similar issues with target_blank function.

I have a list of items in the list page that have some images which are linked to certain item pages where more information can be found about these items. When I click on an item in the list it does not open the relevant/current item page but the one which has been clicked on previously.

For example:
I have images of various fruits in the list page. Let’s say, apples, bananas, oranges, grapes, etc.
When I click on the ‘apples’ image in the list linked to the apples item page, it does open in a new tab which is great, but first time I always have to click on it twice.
Then I click on the ‘bananas’ image in the list linked to the bananas item page, now I have to click once, but it opens the apples item page again instead of the bananas item page in a new tab.
Then I click on the ‘oranges’ image in the list linked to the oranges item page, and now the bananas item page opens in a new tab.
Then I click on the ‘grapes’ images in the list and the oranges item page comes up in a new tab.
And so on…

So it always opens the item page previously click on in the list, except the first one when I have to click twice.
Can anybody explain this strange phenomenon? And does anybody know the solution to my problem? Maybe the memory/cache needs to be refreshed every time? If so, how?

Here is my code:

export function overimage_click(event) {
    console.log(event.context.itemId);

    if (event.context.itemId === "bdd934b6-15bc-4621-9539-69aae74aa4de") {
                 $w("#frimage").link = "https://apples.wixsite.com/...";
    }

    else if (event.context.itemId === "934d4093-73a1-429b-8892-3b714c5a36b6") {
                      $w("#frimage").link = "https://bananas.wixsite.com/..."; 
    }

    else if (event.context.itemId === "ca646ded-1095-4352-85fb-5af3f28beaca") {
                      $w("#frimage").link = "https://oranges.wixsite.com/..."; 
    }

    else if (event.context.itemId === "573dd552-0d51-42b0-97a3-b457c21854a1") {
                      $w("#frimage").link = "https://grapes.wixsite.com/..."; 
    }

 $w("#frimage").target = "_blank";

}

Thank you any suggestion or help!
GyO

Try this one…

export function overimage_click(event) {
    console.log(event.context.itemId);

    if (event.context.itemId === "bdd934b6-15bc-4621-9539-69aae74aa4de") {
        $w("#frimage").link = "https://apples.wixsite.com/...";
        $w("#frimage").target = "_blank";
    }

    else if (event.context.itemId === "934d4093-73a1-429b-8892-3b714c5a36b6") {
        $w("#frimage").link = "https://bananas.wixsite.com/...";
        $w("#frimage").target = "_blank"; 
    }

    else if (event.context.itemId === "ca646ded-1095-4352-85fb-5af3f28beaca") {
        $w("#frimage").link = "https://oranges.wixsite.com/...";
        $w("#frimage").target = "_blank"; 
    }

    else if (event.context.itemId === "573dd552-0d51-42b0-97a3-b457c21854a1") {
        $w("#frimage").link = "https://grapes.wixsite.com/..."; 
        $w("#frimage").target = "_blank";
    }
}

What is —> #frimage?
Is it a button?
Is it a box?
Is it a dropdown?
Is it an apple?
Is it a bannana?

When working with codes, try to give your code a readable structure → using declaration-PREFIXES of your variables, this way you and also other extern coder will be able to read your code much faster and easier.

For sure it is abutton, but if you would declare your butto-element’S variable as the following…

'#btnFrimage' 

…everyone immediately would know that you did no error…
…everybody emmidiately would recognize whats going on on your code.

And your links…

"https://grapes.wixsite.com/..."; 

…they work ?

Hi,
Thanks for the reply. I have tried your version before ( and also now) but it does the same thing, the same strange phenomenon.

  1. Yes the link works, it is not the proper link, just an example.
  2. You are right about the prefixes, I will implement in my code to be more readable.
  3. the frimage is not a button but an image that can be link the same way a button can be. And my code was altered for the example but I forgot to change the overimage to frimage in the first row

so my code corrected to the example is

export function frimage_click(event) {console.log(event.context.itemId);

if (event.context.itemId === "bdd934b6-15bc-4621-9539-69aae74aa4de") 
{$w("#frimage").link =         "https://apples.wixsite.com/...";
$w("#frimage").target = "_blank";}

else if (event.context.itemId === "934d4093-73a1-429b-8892-3b714c5a36b6") 
{$w("#frimage").link = "https://bananas.wixsite.com/...";
$w("#frimage").target = "_blank";}

else if (event.context.itemId === "ca646ded-1095-4352-85fb-5af3f28beaca") 
{$w("#frimage").link = "https://oranges.wixsite.com/...";
$w("#frimage").target = "_blank";}

else if (event.context.itemId === "573dd552-0d51-42b0-97a3-b457c21854a1") 
{$w("#frimage").link = "https://grapes.wixsite.com/...";
$w("#frimage").target = "_blank";}}

Any other suggestions?
Thank you!

If I use the ‘wixlocation to’ function it does the job correctly, it opens the proper item page but it does it in the same tab. I would like to open it in a new tab.
Thanks.

I just recognized that i did not read your post carefully!

This is your PROBLEM…

it does open in a new tab which is great, but first time I always have to click on it twice.

And this is your SOLUTION…

$w.onReady((t)=>{
    $w("#frimage").onMouseIn((event)=>{console.log(event.context);
        $w("#frimage").link = "https://apples.wixsite.com/...";
        $w("#frimage").target = "_blank";
    }); 
});

When you use → onClick() → it is already to late to set the link.
You must set the link → before you click onto the image!
This explains your DUOBLE-CLICKING-ACTION!

Hi,
Thank you. I’m going to try it soon.
What is ‘t’ in

$w.onReady((t)=>

can I change it to something meaningful?

So what to do with the click function, below?

export function frimage_click(event)

Do I need to include it in my code or it is replaced by this code?

$w.onReady((t)=>{
$w("#frimage").onMouseIn((event)=>

Thank you, sorry, I don’t know much about coding.

(t) ← just a typo caused by copy and paste actions.
You can remove the → “t”

Your onClick -trigger was r eplaced byonMouseIn

…the reson for this replacement was…

When you use → onClick() → it is already to late to set the link.

You must set the link → before you click onto the image!

This explains your DUOBLE-CLICKING-ACTION!

Did you already tried the last code i have provided?

$w.onReady(()=>{
	$w("#frimage").onMouseIn((event)=>{
	console.log("Context: ", event.context);
	$w("#frimage").link="https://apples.wixsite.com/..."; 
	$w("#frimage").target="_blank";
	});
});

Test this code first, and then expand the code by adding all the rest of your wished functions.

Also take a closer look what you get in console…

Can you show the → OUTPUT for…

console.log("Context: ", event.context);

…what do you get as results in console?

Hi,
I have tried it and it works fine now. THANKS A LOT!

If I expand the brackets of the log output I get this info when I hoover the mouse over one of the items in the list.

Context:  


{...}
jsonTableCopy JSON

type: 
"COMPONENT_SCOPE"

itemId: 
"573dd552-0d51-42b0-97a3-b457c21854a1"

_internal: 
{...}
jsonTableCopy JSON

repeaterCompId: 
"comp-kyalmyde"

Is it fine? Thanks

If it already works fine, than i have no questions anymore :stuck_out_tongue_winking_eye:

THAAAAAAAAAAAANKS!!!
:grin:

Hi Everyone,

As Velo-Ninja suggested the
the " onClick -trigger was r eplaced byonMouseIn"
It works fine on laptops and computer where you use mouse but I have the same issue using phone.
People tap with fingers and it acts as (or similar to) clicks on laptops or computers.
The DUOBLE-CLICKING-ACTION is still there on my phone, unfortunately.

Any suggestion how to solve it?
Thanks for any reply!

Just load it directly when REPEATER gets load, without waiting for any ACTION, like a (MouseOver or a Click).
When REPEATER gets READY → paste all the links to all the Buttons inside of repeater.

But wait!!! Do you use a —> REPEATER ???

If not, why you don’t use it?

A —> REPEATER is the …

…element!

Hi,
Thanks.
I use repeater.
I have certain items in the repeater. If anyone wants to open a page using mouse by clicking on one of the items in the repeater, everything is fine because the onmouse function refresh/update the info before anyone clicks on a certain item.
But this is not the case with phone where someone taps it and there is no mouse to hover over it and therefore no update occurs.
Thus the double-click action is needed. If an item is tapped it opens the previous page in a new window which had been tapped before the current one.
I hope you understand it.
Thanks for any help!