Open multiple external Links for a List

Hi there!
I have a list of items and each item has a link attribute with a website in it. Now if the user presses a button I want all links of all the items to be opened in a new tab. Is that even possible somehow?
I already tried it with javascript
window.open(Items:each items itemlink, “_blank”);
But there is a problem with this.
It only opens the links to internal websites (e.g. mywebsite/itemlink1,itemlink2,itemlink3) and as you see in my example it clumps them up together. But I need them to be in external tabs and for each itemlink there should be a tab opened up.

Thanks in advance for any help!

Hi @c.wittelsberger :wave:

Ok, because your code is not right.

Bubble will interpretate the expression “Items:each items itemlink” as a string composed by all your links separated by comma, like:

www.bubble.com, www.google.com, www.apple.com

You will need to create a loop to keep opening all the links of your array. Do you have any experience in javascript?

Hey @rpetribu!

Yes I know a bit of coding. So a for loop should be

for (let i = 1; i < Items:count; i++) {
window.open(items:item #i’s itemlink, “_blank”);
}
But I run into two problems. First problem I cant enter items:item #i into the workflow it always marks it as red when I enter the “i” in there. And the second problem is still, that it would still only the itemlinks on my website and not on external websites.

You have an idea how to fix that @rpetribu ?
Thanks in advance for your help!

Can you share an image of your editor / javascript?

Regarding your main problem…

You need to place HTTPS:// before your link. :+1:

Ah okay thanks!
Im currently on the road so I can only send you a screenshot tomorrow. But I can try to explain my problem.
I enter the code for the loop, so that it loops as long as i < items:count, so the loop goes through all items. But in the body of the loop I have to open each link of the items so i have to put the “window.open” codeline in there for item #i’s itemlink. But whenever I come to the point where i have to enter the “i” after the “item#” the workflow editor deletes it and goes red. I guess because it cant handle “i” as variable.
I hope you understand what I mean :see_no_evil: Otherwise I will upload a screenshot tomorrow. And thanks again for your help !

@rpetribu I found another screenshot on the forum of a person who had the same problem as mine. Unfortunately he doesent really explain how he fixed it :zipper_mouth_face:

The trick is to save your links as an array inside your javascript.

I made an example for you… You can take a look in this code working here. :wink:

Thanks so much for your help!

1 Like