8 examples of 'onclick window location href' in JavaScript

Every line of 'onclick window location href' 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
231function after_setWindowLocation(win, url) {
232 goog.dom.safe.setLocationHref(win.location, url);
233}
12function onClick (e, href) {
13 e.preventDefault()
14 window.getGlobal('openExternal')(href)
15}
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}
26function openPopup (href) {
27 if (window.popup && !window.closed) window.popup.close();
28 var width = 1000;
29 var height = 800;
30 var x = (screen.width / 2) - (width / 2);
31 var y = (screen.height / 2) - (height / 2);
32 var win = new BrowserWindow({
33 width, height, x, y,
34 center: true,
35 autoHideMenuBar: true,
36 webPreferences: {
37 webSecurity: true,
38 nodeIntegration: false,
39 plugins: true,
40 },
41 });
42 win.id = 'popup';
43 win.loadURL(href);
44 window.win = win;
45 /*
46 nw.Window.open('app/popup.html?href=' + encodeURIComponent(href), {x: left, y: top, width: w, height: h},
47 function (win) {
48 window.popup = win.window;
49
50 // do not open the window and open it in external browser
51 win.on('new-win-policy', function (frame, url, policy) {
52 policy.ignore();
53 nw.Shell.openExternal(url);
54 });
55
56 win.window.id = 'popup';
57 win.window.config = App.config;
58 win.focus();
59 });
60 */
61}
210openExternalLink(href) {
211 const a = document.createElement('a')
212 a.href = link
213 a.target='_blank'
214 a.click()
215}
43linkClicked (e) {
44 if (e.currentTarget.nodeName === 'A' &&
45 (e.metaKey || e.ctrlKey || e.shiftKey || (e.nativeEvent && e.nativeEvent.which === 2))) {
46 // ignore click for new tab / new window behavior
47 return
48 }
49
50 const { shallow } = this.props
51 let { href, as } = this
52
53 if (!isLocal(href)) {
54 // ignore click if it's outside our scope
55 return
56 }
57
58 const { pathname } = window.location
59 href = resolve(pathname, href)
60 as = as ? resolve(pathname, as) : href
61
62 e.preventDefault()
63
64 // avoid scroll for urls with anchor refs
65 let { scroll } = this.props
66 if (scroll == null) {
67 scroll = as.indexOf('#') < 0
68 }
69
70 // replace state instead of push if prop is present
71 const { replace } = this.props
72 const changeMethod = replace ? 'replace' : 'push'
73
74 // straight up redirect
75 Router[changeMethod](href, as, { shallow })
76 .then((success) => {
77 if (!success) return
78 if (scroll) {
79 window.scrollTo(0, 0)
80 document.body.focus()
81 }
82 })
83 .catch((err) => {
84 if (this.props.onError) this.props.onError(err)
85 })
86}
21function popup(mylink, windowname)
22{
23 if (! window.focus)
24 {
25 return true;
26 }
27 var href;
28 if (typeof(mylink) == 'string')
29 {
30 href=mylink;
31 window.open(href, windowname, 'width=400,height=200,scrollbars=yes');
32 return false;
33 }
34 else
35 {
36 href=mylink.href;
37 window.open(href, windowname, 'width=400,height=200,scrollbars=yes');
38 return false;
39 }
40}
13onClick(e) {
14 if (this.props.disabled) e.preventDefault();
15 else if (this.props.target === '_blank') {
16 e.preventDefault();
17 shell.openExternal(this.props.to);
18 }
19}

Related snippets