Reload page if user has no javascript enabled - php

is there way to reload a web-page, when javascript is disabled in the brwoser?
I mean, if the user visits the page first time, and has no javascript enabled, the page reloads with a get parameter like page.php?js=false.
Maybe, thanks for hints.

The only way you could force a page reload, without javascript, is by use of a meta refresh tag. However, this is the wrong way to go: better display that page for the javascript-deprived, and redirect those who DO have javascript to a more appropriate page instead.

<noscript>
<meta http-equiv="refresh" content="2;url=page.php?js=false" />
</noscript>
You can use <noscript> tag with refresh <meta> tag.

Adding to Sarfraz's post, you could do this, to match your request:
<noscript>
<meta http-equiv="refresh" content="2;url=page.php?js=false">
</noscript>

You can do it the other way around:
Assume javascript is not available, and
redirect using javascript to page.php?js=true.

Related

check if javascript is available and redirect if javascript is not available [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to detect if JavaScript is disabled?
In my php application i need to check whether the javascript is turn on or not in browser. I have tried this <noscript><p>javascript is off<p></noscript> it's working fine.But i need to redirect to a page if javascript is OFF so developed like this
<noscript>
<?php header('Location: index.php');?>
</noscript>
But i/ts always redirecting to index.php, there is any way to do this.
your solution clearly cannot work, since php is executed before the page is served on client
you could instead do something like
<noscript>
<meta http-equiv="refresh" content="0;URL='http://example.com/'">
</noscript>
in the head of your document
<noscript><meta http-equiv="refresh" content="1;url=error.html"></noscript>
try this to redirect if JS is disabled
Php script runs independently of js
There are known issues with noscript
Instead do this:
<html>
<head>
<script>
window.location.href="javascriptEnabled.html";
/*Since javascript is enabled redirect to javascript based page*/
</script>
</head>
<body>
Showing Static Website since javascript is not enabled..
</body>
</html>
There is not a good way to do it, because without client side interactivity, you can not get information back from the client.
You could do something like this...
Set up a meta redirect to trigger after 5 seconds
use javascript to override the meta redirect
Therefore, if javasccript is enabled, you get to the javascript page, otherwise the non javascript page
It does redirect to index.php because the <?php header('Location: index.php');?> is processed by the server while the <noscript> is processed by the client ..
A correct way to do this is to set a cookie using javascript on the client, then check for the cookie's presence with php on the server, If the cookie does exist, then javascript is on, Else, it's off.
You could use a different approach here
Use the no javascript version as default version
Use a javascript redirect to the enhanced version
Remember it's better to not have separate versions of the site. You could progressive enhancement with libraries as http://modernizr.com/ or https://github.com/filamentgroup/enhance

Multibrowser refresh/reload page

I was using this code to reload the page, however I'd only tested it on Chrome and when I tried it on Firefox I realized it didn't work. How do I make it work in other browsers?
echo 'Reloading. <META HTTP-EQUIV="refresh" CONTENT="0">';
Thanks
Instead of pushing out invalid HTML, instead, send the actual header using PHP's header function.
header("Location: http://where.you/want/to/redirect.to");
If the page has already loaded (even partially), then this approach will not work -- in that case, either using JavaScript or the <meta> tag will do the trick -- just remember that the <meta> tag must be added to the <head> portion of your HTML file.
<script type="text/javascript">window.location.reload(true);</script>
What you are doing is telling the browser to refresh. However, the <meta> tag you are using is meant to be in the <head> part of the document. That is probably why Firefox isn't properly executing it.
If you instead use the blurb above, which is javascript, you can put that code virtually anywhere in the document and it will cause the page to refresh.
My guess is that it's not working because it's not in the <head> tag. Generate a properly formatted HTML document and it should work. But why in the world would you want to refresh the page after zero seconds?

Meta page refresh not working for php page?

i am trying to redirect users without javascript enabled to our help page (help.php), specifically the part that talks about enabling javascript (help.php#nojavascript).
however, my meta refresh is not working! it keeps on refreshing the same page! i tried redirecting to a different page with a .html extension instead, and that works, so why doesn't this work?
...
</script>
<!-- if user doesn't have JS enabled, take them to help page -->
<noscript>
<meta http-equiv="Refresh" content="3;url=help.php" />
</noscript>
</head>
...
Try to use an absolute path:
<META HTTP-EQUIV="Refresh" CONTENT="3;URL=http://www.some.org/some.html">
For one thing, try taking it out of the NOSCRIPT element. Browsers with scripting enabled are supposed to ignore everything inside NOSCRIPT.
i was including a file that redirected the user to home.php =( sorry!

setting a url as visited

I have a
my_text
link on my page, and the following line in my_redirect_page.php:
header("Location: ".$mylink);
but after the redirection, if I click on back in my browser, the "my_text" for the link does not appear as visited (in purple, instead of blue). How do I work around this? Is there a way to change the visited property in php or javascript?
Thanks,
Dave
Not a terrific solution, but, in my_redirect_page.php:
<html>
<head>
<title>Redirecting...</title>
<meta http-equiv="refresh" content="0; url=<?php echo $_GET['link']; ?>">
</head>
<body>
Redirecting to <?php echo html_entities( $_GET['link'] ); ?>.<br>
If you are not redirected, click here.
</body>
</html>
Or something like that - the Page should load (thereby entering into the browser history) and then, with a delay of 0, load the targeted URL. Should, for some reason, the redirect fail, the user will see a page containing a link to the targeted URL.
I'm not sure this is possible, unless you change the way your redirects are done.
[This question][1] is basically a duplicate of yours, and the consensus was that none of the browsers allow you to set pseudo-classes (like :visited).
The easiest way to simulate it for the user is to set a CSS class which colours the link to look the same as a browser default or CSS-style visited link, which you can easily do in your view layer or by adding the class using javascript if the link appears in window.history.
You may also be able to push elements onto the window.history array, and have them appear in the browser history (and hence be given the :visited pseudoclass), but I'm not sure if that would work. Worth a try though.

<noscript> redirection

I want to redirect the user to a certain page if he/she has javascript disabled. I tried this code:
<noscript><?php url::redirect('controller/method'); ?></noscript>
// url::redirect is much like the location header
to no avail...
How do I do this?
Since the headers have already been sent, you'll need to use standard HTML markup:
<noscript>
<meta http-equiv="refresh" content="0;url=noscript.html">
</noscript>
Trying this on both Firefox and IE seems to work well... With JavaScript enabled, the <meta> tag is ignored. When it is disabled, the browser redirects to noscript.html.
There is no way to do a redirect based on if javascript is disabled. Why not do the opposite - redirect if javascript is enabled?
<script>
window.location = "...";
</script>
You can't use meta refresh tag then remove it using Javascript because the browser is set to redirect upon reading the meta refresh tag and it's too late for JS to manipulate it.
The only way is to either do what Daniel suggested, or to show up a link when there's no Javascript:
<noscript>
Click here to continue
</noscript>
Or you can try to fail gracefully: Do you plan for javascript being off?
Add this as the first element in your body, style it to suit, and perhaps offer a link inside of it to a noscript page:
<div onload="return false;">
<!-- PAGE CONTENTS -->
</div><noscript>JAVASCRIPT IS REQUIRED TO VIEW THIS PAGE</noscript>
I use a more verbose method of this (that basically makes it appear as a modal dialog and all pretty) on pages where a client does not allow me to use more compatable means. I've tested in IE6+ and all other major browsers with great success.

Categories