JavaScript String link(): Legacy Reference

String.prototype.link() is deprecated and kept only for backward compatibility. For new JavaScript, create an <a> element with the DOM and set its href and text explicitly.

const text = "Visit Plus2net";
console.log(text.link("https://www.plus2net.com")); // legacy only

Legacy link() syntax Top ↑

string.link(url)

The method returns a string containing anchor markup.

Original style of use Top ↑

const label = new String("Welcome to plus2net.com");
console.log(label.link("https://www.plus2net.com"));

This explains old code you may encounter, but it is not the recommended implementation.

Create a link with the DOM Top ↑

const link = document.createElement("a");
link.href = "https://www.plus2net.com";
link.textContent = "Visit Plus2net";
document.body.append(link);

Change a link based on user choice Top ↑

function setSearchEngine(engine) {
  const link = document.getElementById("searchLink");
  link.href = engine === "google"
    ? "https://www.google.com"
    : "https://www.yahoo.com";
}

This replaces the original document.write() + radio-button approach without replacing the whole document.

Safe link handling Top ↑

When a destination comes from untrusted data, allowlist acceptable protocols and destinations. For new-tab links, use rel='noopener' where appropriate.

Legacy demo Top ↑

The original behavior is preserved in the link demo for historical reference.

Previous / String Reference Next related topic




Subscribe to our YouTube Channel here



plus2net.com










We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2026   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer