Prevent Randomised Button Opening Link In New Tab

Hi everyone,

I have added a button to my website that takes the user to a random page on my website when clicked. It works great, other than one issue.

The button opens the page in a new tab. Since the button will be clicked frequently, it will become very spammy for the user.

I want my links to open in the same tab, so the website can be naviagted within one tab.

I have attached the code. Any help would be greatly appreciated!

Hi,
Check out this reference for more information.

$w('#myButton').target = "_self";

Good luck!
Roi.

Hi Roi, thanks a lot for the help,

I switched #mybutton to #button1 and I have been playing around with the code to try to get it to work. I’m having some difficulty finding where in the code I should insert $w(’ #b utton1’).target = “_self”;. I have tried lots of variations but it just results in the button not working at all.

The reference doesn’t seem to mention where things should go and I have zero coding experience. I’d greatly appreciate it if you could let me know which lines it should be inserted between!

Hi,
It should be right before $w(‘#button’).link.
You should start learning :slight_smile:
w3school, codecademy and mdn are pretty good.
Good luck!
Roi.

Hi,

I tried two versions and both of them result in the button not working (left click disabled). Are either of these two what you meant?

I agree it would be useful, I tried C# and Python a few years ago but I was never very good at learning them.