Reputation: 2758
I'm trying to create a full ajax based website. For now i'm just researching how it all works. The best example i think is Twitter. Twitter does something when no javascript is enabled, but i'm unable to find out how. When you disable javascript and go to twitter, '?_twitter_noscript=1' is appended to the url. Any idea how they do this?
kind regards,
Daan
Upvotes: 1
Views: 695
Reputation: 1411
with me, the Twitter don't work with javascript disabled. i have success with this code created by me:
in index.php
<?php
if (!isset($_SESSION)) session_start();
$url = !isset($_SESSION['ajaxpage']) ? '' : $_SESSION['ajaxpage'];
$_SESSION['ajaxpage'] = '';
if (!isset($_GET['noscript'])) echo '<noscript><meta http-equiv="refresh" content="0; URL=/'.$url.'?noscript=1" /></noscript>';
?>
in each php file i call _head.php that contains:
<?php
if(!isset($_GET['ajax'])){
if (!isset($_GET['noscript'])){
if (!isset($_SESSION)) session_start();
$_SESSION['ajaxpage'] = $ajax_page;
header('Location: /#!/'.$ajax_page);
} else {
// normal functions, requires... of all pages
}
}
?>
in each php file i have var with the link to page, like:
<?php
$ajax_page = '/contact/'; //change this for each page
include_once('_head.php');
?>
so, that's it! each ajax load, please join '?ajax' to url, like:
$("body").delegate("a", "click", function(event){
var lnk = $(this).attr("href");
var addAjax = lnk.indexOf('?')>0 ? "&ajax" : "?ajax";
$("#content").load("/"+lnk+addAjax);
});
Upvotes: 0
Reputation: 851
Twitter uses meta refresh when Javascript is disabled.
I found the following code in source of http://www.twitter.com when Javascript is enabled:
<noscript>
<meta http-equiv=refresh content="0; URL=/?_twitter_noscript=1" />
</noscript>
Note: The source of http://twitter.com/?_twitter_noscript=1 will not have this code
Upvotes: 1
Reputation: 4146
They have a hidden input on their signup form:
<input id="redirect_after_login" name="redirect_after_login" type="hidden" value="/?_twitter_noscript=1" />
When script is enabled, that changes to:
<input id="redirect_after_login" name="redirect_after_login" type="hidden" value="/" />
So my assumption is that they have some JavaScript changing the value of that input.
Upvotes: 3