4 examples of 'js go to link' in JavaScript

Every line of 'js go to link' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
1function jsOpenLink() {
2 // find elements with attribute data-linkto
3 const el = document.querySelectorAll('[data-linkto]');
4
5 // define function to grab URL from data-linkto, open in new tab
6 function jsLinkClicked() {
7 const url = this.getAttribute('data-linkto');
8 window.open(url, '_blank');
9 }
10
11 // find any anchor tags within the clickable parent
12 const childLinks = document.querySelectorAll('[data-linkto] a');
13
14 // prevent children from executing the parent click event
15 Array.from(childLinks).forEach(link => {
16 link.addEventListener('click', e => {
17 e.stopPropagation();
18 });
19 });
20
21 // attach click event listener to the parent
22 Array.from(el).forEach(element => {
23 element.addEventListener('click', jsLinkClicked);
24 });
25}
168function gotoLink( s )
169{
170 $.mobile.changePage( s );
171}
377function LinkToJson(){
378
379 var val = $id("RawJson").value;
380
381 val = escape(val.split('/n').join(' ').split('/r').join(' '));
382
383 $id("InvisibleLinkUrl").value = val;
384
385 $id("InvisibleLink").submit();
386
387}
221function LinkToJson(){
222 var val = $id("RawJson").value;
223 val = escape(val.split('/n').join(' ').split('/r').join(' '));
224 $id("InvisibleLinkUrl").value = val;
225 $id("InvisibleLink").submit();
226}

Related snippets