I am making a web site and I was wondering how I would redirect the user to a different website if Javascript is not enabled. I can't use <noscript> because It needs to redirect. Could I put a meta tag inside a noscript tag? Thx.

Dani AI

Generated

Short answer: yes — a meta-refresh inside a <noscript> placed in the document <head> is allowed by the HTML spec and will redirect many users who have scripting disabled, but it is a brittle fallback and not a substitute for a server-side redirect. See the spec for <noscript> and the <meta> element for details (WHATWG noscript, MDN meta element).

Both approaches already suggested in this thread are useful: pointed out the meta-refresh option and showed the client-side redirect for JS users. Recommended pattern is to combine techniques rather than rely on one single trick: serve a usable baseline (no-JS) page, use a short client-side redirect for JS-capable users, and provide a <noscript> fallback that either performs a meta refresh or shows a clear clickable link for users and assistive tech. Keep any automatic refresh short (1–3s) and include a visible fallback message so users who are blocked from automatic redirects still have a route forward.

If reliability and SEO matter, prefer server-side handling. One robust technique is a small cookie “handshake”: first request sets a cookie from JavaScript and reloads; the server checks that cookie and then can perform an HTTP redirect for JS-capable clients while leaving non-JS clients on the baseline page. Example (server-side PHP + tiny JS):

<?php
// at top of the PHP page, before any output
if (empty($_COOKIE['js_enabled'])) {
    // first visit: send a tiny page that sets a cookie and reloads
    echo '<!doctype html><html><head><meta charset="utf-8"><script>document.cookie="js_enabled=1;path=/";location.reload();</script></head><body>Loading…</body></html>';
    exit;
}
// cookie present: perform server-side redirect for JS-capable clients
header('Location: /js-version/');
exit;
?>

Drawbacks: the handshake adds an extra round-trip, needs testing across crawlers and proxies, and may complicate caching. For simple cases, prefer the combined approach (JS redirect + <noscript> link/meta) and test in multiple browsers and search-engine user agents.

Recommended Answers

All 2 Replies

Please find below a meta tag for re-direction,

<meta http-equiv="refresh" content="2; url=http://www.somedomain.com.com/" />

In content attribute you will have to pass two values:
1: time in seconds.
2: the target url.

However I am not sure about browser/platform compatibility of this script.

But hopes this works for you... Good Luck!

The only way I can think to do it would be to have it redirect if they DO have javascript, else they see the regular noscript page. Like so...

<script type="text/javascript">
window.onload = function {
location.href='';
return true;
}
</script>

That way if they don't have javascript they never get redirected...
But if they do...wha la!! Off to the js version of your site.

But there's no way to check (client side) if they don't have js, without using...javascript!!

The above plan should get around that though.

good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.