How to add hyperlink

How to add links to a button in app tab?
Help me as soon as possible

Here’s a simple function to help you out in this:

function hyperlinkButton(id, link) {
  onEvent(id, "click", function( ) {
    window.open(link);
  });
}

Usage:

hyperlinkButton("button1", "https://youtube.com/");

This will assign a link to a button. You need to have created that button already, and then have put the id and the link in a function.

@alsotechyofficial -

If you are using blocks in App Lab, the following will work as well:

~Michelle

1 Like

That is literally what I had written though? I just made it easier because it’s a function you can paste and it’s one line.

@IMPixel,

Always thankful for your help especially with the more advanced posts. I always learn something from them! My approach was considering the poster might be new to teaching CS (or new to CS) as many Code.org users are and therefore may prefer blocks. Just covering the bases.

~Michelle

1 Like

Oh thanks, it’s ok, I was just wondering.

1 Like

You can import the Link library into your code by going to Manage Libraries → Import Library from ID → then paste dR4BIBYsaPqybX21RevLykJg57yMONOHAPY9aF-dYS0 and press Add.
After the library is imported, make an onEvent block similar to @melynn’s example, but add the following code:

Link.link('google.com',true);

You can replace google.com with your link and it will take you there instantly.

Thank you so much Michelle . I appreciate for you work!

1 Like

Note that @letti42’s way bypassees the prompt for all links that aren’t created by code.org.