10 examples of 'onclick open url in same window' in JavaScript

Every line of 'onclick open url in same window' 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
81export function openWindow(url) {
82 if (isIE11() || isFirefox()) {
83 const win = window.open();
84 win.opener = null;
85 win.location = url;
86 return;
87 }
88 const anchor = document.createElement('A');
89
90 anchor.setAttribute('rel', 'noreferrer nofollow noopener');
91 anchor.setAttribute('target', '_blank');
92 anchor.href = url;
93
94 return anchor.click();
95}
270openLink({ href, target, currentTarget, metaKey }) {
271 let resolved = href || this.resolveHref(target || currentTarget);
272 if (!resolved) {
273 return;
274 }
275 if (target && target.closest('.no-open-link-events')) {
276 return;
277 }
278
279 let { protocol } = url.parse(resolved);
280 if (!protocol) {
281 protocol = 'http:';
282 resolved = `http://${resolved}`;
283 }
284
285 if (['mailto:', 'mailspring:'].includes(protocol)) {
286 // We sometimes get mailto URIs that are not escaped properly, or have been only partially escaped.
287 // (T1927) Be sure to escape them once, and completely, before we try to open them. This logic
288 // *might* apply to http/https as well but it's unclear.
289 const sanitized = encodeURI(decodeURI(resolved));
290 remote.getGlobal('application').openUrl(sanitized);
291 } else if (['http:', 'https:', 'tel:'].includes(protocol)) {
292 shell.openExternal(resolved, { activate: !metaKey });
293 }
294 return;
295}
210openExternalLink(href) {
211 const a = document.createElement('a')
212 a.href = link
213 a.target='_blank'
214 a.click()
215}
48function openExternal (e, url) {
49 e.preventDefault()
50 shell.openExternal(url)
51}
37openUrl(url) {
38 opn(url);
39}
9export async function openUrl(url: string): Promise {
10 // Using this functionality is blocked by https://github.com/Microsoft/vscode/issues/25852:
11 // await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url));
12
13 // tslint:disable-next-line: no-unsafe-any
14 opn(url);
15}
47export function openUrl(url) {
48 testing ? console.log(url) : open(url, { wait: false })
49}
93function openUrlNewTab(url)
94{
95 chrome.tabs.create({url: url});
96}
14function open_in_new_tab(url )
15{
16 var win=window.open(url, '_blank');
17 win.focus();
18}
268openLink(url: string) {
269 fin.desktop.System.openUrlWithBrowser(url)
270}

Related snippets