6 examples of 'javascript redirect to relative url' in JavaScript

Every line of 'javascript redirect to relative url' 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
this disclaimer
68function redirect(text = null) {
69 if (text == null) {
70 text = document.querySelector('#search-box').value;
71 }
72 location.href = '/?q=' + encodeURIComponent(text);
73}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

50function redirect()
51{
52if (second < 0)
53{
54 <!--定义倒计时后跳转页面-->
55location.href = '/sba';
56} else
57{
58if (navigator.appName.indexOf("Explorer") > -1)
59{
60document.getElementById('totalSecond').innerText = second--;
61} else
62{
63document.getElementById('totalSecond').textContent = second--;
64}
65}
66}
310function redirect(url) {
311 var
312 hash_pos = url.indexOf('#'),
313 query_pos = url.indexOf('?'),
314 hash = '';
315 if (hash_pos >=0 ) {
316 hash = url.substring(hash_pos);
317 url = url.substring(0, hash_pos);
318 }
319 url = url + (query_pos >= 0 ? '&' : '?') + 't=' + new Date().getTime() + hash;
320 console.log('redirect to: ' + url);
321 location.assign(url);
322}
519function redirectTo(url) {
520 setBubbleText(t('redirecting', { hostName: util.hostNameFromUri(url) }));
521 addClass(elements.bubble, 'one-line');
522 setTimeout(function() {
523 document.location = url;
524 }, 500);
525}
62function redirect(url, param) {
63 if (!url)
64 return;
65
66 var _param = param || {};
67 var formId = 'redirectForm' + new Date().getTime();
68 var formHtml = "<form id='{0}' method='post' action='{1}'>".format(formId, url);
69
70 Object.keys(_param).forEach(function (aProperty) {
71 if (_param[aProperty]) {
72 formHtml += "<input type='hidden' name='{0}' value='{1}'/>".format(aProperty, _param[aProperty].toString());
73 }
74 });
75
76 formHtml += '</form>';
77 $(formHtml).appendTo('body');
78
79 $('#' + formId).submit();
80}
47function redirectBrowserTo(url)
48{
49 $window.location.href = url;
50}

Related snippets