2 blueyed Sep 06, 2006 00:16
![](https://forums.b2evolution.net/media/users/blueyed/profile_pictures/.evocache/181421514044d4f24b94ee9.jpg/crop-top-80x80.jpg?mtime=1372015408)
But then both users suffer from having to download useless data. And the javascript users suffer as well from the extra load time.
And in some cases the layout changes signifcantly.
Just finished having a chat with Yabba, and he told me a way to solve all the problems;
<script type="text/javascript">
document.write('<script type="text/javavscript" src="......."> ......
So if javascript is enabled it will include the javascript files to enhance the site :)
Thus making it so no one gets disadvantaged.
Actually thinking about it some more that still causes problems, as the javascript would need to alter the page instead the php outputting the altered page. Which would cause a lot more work for the developer, and a much larger load time the user....
So i think the setting the javascript variable is still the best option...
So in the head of a page have something like
<?php
if ( !isset($GLOBALS['javascript']) )
{
if ( isset($_GET['javascript']) )
{
$GLOBALS['javascript'] = $_GET['javascript'] === 'true';
setcookie('javascript', $GLOBALS['javascript'] ? 'true' : 'false');
} else
{
if ( isset($_COOKIE['javascript']) )
{
$GLOBALS['javascript'] = $_COOKIE['javascript'] === 'true';
} else
{ // There is no choice defined, meaning that javascript is definitly disabled
// If javascript is enabled, but wanted to be turned off then it wouldn't reach here.
$GLOBALS['javascript'] = false;
?>
<script type="text/javascript" >
document.location = document.location+'?javascript=true';
// add a check in the above to see if the ? is there or not, if it is use a & instead
document.write('</script></head></html>');
</script>
<?php
}
}
}
if ( $GLOBALS['javascript'] )
{
// output the js includes and output the js enhanced page
}
?>
If anyone can think of a better way get back to me.
And if they have javascript enabled and cookies disabled?
¥
Then they can stop being wierd ;) :P
But the code would still work even if you have cookies disabled as the javascript=true should hang around in the url if the page is created properly.
Do you have a new suggestion?
Should I tell you that I also have flash disabled by default? ;)
Sure, look into degradation more ;)
¥
You already told me you have flash disabled, but i can understand that.
But cookies, i mean, why on earth would u have them disabled :S
Javascript is understandable as well.
All this looking into, grrrrrrrrr.
Why would I want cookies enabled by default? Hell, might as well enable js for _urchin.tracker whilst I'm at it?
Degradation is about starting with what you can rely on to be there and then enhancing from that. It's not about js ;)
¥
Everything i find, are things like, import javascript, add a onloadevent, then modify the page via javascript.
Sorry, but i totally disagree with this, why should users that do have the capabilities for a enhanced site be disadvantaged. It should be the other way round, or at best no disadvantage either way.
Having javascript modify the page increases load times and is a lot of work for the developer rather than the better method of just outputting the enhanced code via php.
The php code should generate two different pages, one with enhanced/javascript content if javascript is avaliable, and the basic one if its not.
Now you just need a way, which does not disadvantage either user, espicially not the javascript enabled user, of detecting and displaying the approriate page.
There is no way, i'm going to make javascript that has to modify my page's design in order to add the enhanced functionality.
Now givin this fact, i could still develop my site normally, use that javascript including it's own js files script, and then use unobtrusive javascript techniques so by clicking a item with js enabled you get the enhanced thing, clicking it without it enabled you get the basic thing, without any changes in code. This could even apply to the Panels that you may of seen on my site once upon a time.
Now a refresh on panels;
| Title | Show/Hide | Close |
| C o n t e n t |
Now using the above method i described, all would be find and dandy for the js enabled user, but for the js disabled user they would be seeing some useless show/hide and close buttons.
Now as i was writing that, i guess i could do a css approach to that, and have the buttons hidden by default and with js enabled the defined style is changed, so i would have;
.js_hidden { display:none; }
and with js enabled i would inlude a .css that would contain
.js_hidden { display:block; }
but even display:block; could cause some display problems if a css item is not a block.
Plus it still partly goes against modifying the design via js, which disadvantages js enabled users.
So yeh, i'm honestly sick of researching and finding the same crap on it.
So unless someone can point something out that will fix the problems i have outlined then i dunno...
You could always just code for IE? After all, most people use it (and have js, cookies and flash) and save yourself the extra coding and server loading/resources for the minimal amount of users that don't fit the profile?
¥
lol, ¥åßßå.
@balupton, again:
Make the page work without cookies (you can assume that session cookies work in 99,9%, but persistent not) and Javascript. Then enhance from there.
About the close etc buttons: why shouldn't they work without JS?
If you want to hide it by CSS, use style.display = '' to show it normally ("block" or "inline").
Just enhance the existing, basic page, using javascript.
If there's no javascript available, nothing happens.
Simple.. :D
E.g.,
in a FORM's SELECT, where changing the value should submit the form, use
and then for the non-JS people use:
Another example would be to use regular DOM functions (e.g. document.getElementById()) to attach events, properties etc to elements.