|
|
 |
|
December 23rd, 2007, 09:31 AM
|
#1
|
|
Highly Reputable Member
Join Date: Jul 2007
Location: Cork, Ireland
Posts: 828
Thanks: 1
Thanked 2 Times in 2 Posts
Rep Altering Power: 0
|
[SOLVED] Showing something on a page - only if they have Javasciprt disabled.
I want to make my site accessible whether they have JavaScript enabled or not.
I am going to place the content that's in the JavaScript in a <noscript></noscript> part - but, I want the actual JavaScript to not show when a user has it disabled.
http://simplifiedimpact.com/beta2.html
What I have is the fx.slide from MooTools, which the content from that, I want to place under the big image when they have JS disabled, not above it.
I was thinking that I but tags around the fx.slide box that showed it only is JS was enabled, and place the content under the big image in <noscript> tags.
Like this:
How would I do this without repeating in content above and below the image? I basically want the opposite of <noscript>
Thanks,
Ed
Last edited by Ed; December 23rd, 2007 at 02:04 PM..
|
|
|
December 23rd, 2007, 01:17 PM
|
#2
|
|
Most Reputable Member
Join Date: Oct 2007
Location: UK
Posts: 1,633
Thanks: 22
Thanked 84 Times in 79 Posts
Rep Altering Power: 0
|
Re: Showing something on a page - only if they have Javasciprt disabled.
I'm not sure what you want to do is completely possible. In other words, you want certain content to be in a different place, depending on the user's javascript support?
I guess you could use javascript to actually write the content at runtime, then have the page content in HMTL below the image in <noscript> tags.
Or...use a server-side script to detect javascript support, then output the correct HTML accordingly.
Or.... (now this is last resort  ) use javascript to write a few CSS styles to position your content absolutely above the image, but code it below the image in your HTML. Then if javascript is off, things will display ' as is'.
|
|
|
December 23rd, 2007, 02:05 PM
|
#3
|
|
Highly Reputable Member
Join Date: Jul 2007
Location: Cork, Ireland
Posts: 828
Thanks: 1
Thanked 2 Times in 2 Posts
Rep Altering Power: 0
|
Re: Showing something on a page - only if they have Javasciprt disabled.
Actually, all I want to do is hide the slide button and the welcome image if they haven't JS enabled. Even though it is javascript - it still appears even when I disable it. I don't want people to be confused as to what the hell the slide button is.
Is there an opposite of <noscript> ?
Thanks,
Ed
Last edited by Ed; December 23rd, 2007 at 02:09 PM..
|
|
|
December 23rd, 2007, 02:13 PM
|
#4
|
|
Most Reputable Member
Join Date: Oct 2007
Location: UK
Posts: 1,633
Thanks: 22
Thanked 84 Times in 79 Posts
Rep Altering Power: 0
|
Re: Showing something on a page - only if they have Javasciprt disabled.
I see
Not that I know of. You could set the button and welcome image to display:none then override it with javascript to display:inline. It's not the best approach, but it's an easy fix. Just found an article that should help out with that ( link)
|
|
|
December 23rd, 2007, 02:16 PM
|
#5
|
|
Highly Reputable Member
Join Date: Sep 2007
Age: 17
Posts: 716
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Re: Showing something on a page - only if they have Javasciprt disabled.
Just do this:
<script type="text/javascript">
var code = '<a id="toggle" href="#" name="toggle"><img class="imageslide" src="http://simplifiedimpact.com/images57/slidebutton.jpg" alt="Slide"></a>';
document.write(code);
</script>
That should do it!
|
|
|
December 23rd, 2007, 02:40 PM
|
#6
|
|
Highly Reputable Member
Join Date: Jul 2007
Location: Cork, Ireland
Posts: 828
Thanks: 1
Thanked 2 Times in 2 Posts
Rep Altering Power: 0
|
Re: Showing something on a page - only if they have Javasciprt disabled.
Code:
<script type="text/javascript">
var code = '<h3 class="section">
<img src="http://simplifiedimpact.com/WELP.jpg" alt="Welcome" />
<a id="toggle" href="#" name="toggle"><img class="imageslide" src="http://simplifiedimpact.com/images57/slidebutton.jpg" alt="Slide" /></a></h3>
<div id="test">
<img id="ready" src="http://simplifiedimpact.com/nobinoculars.jpg" alt="Ready?" /><br />
Yes, we design beautiful websites that are extremely simple, yet have some serious impact.<br />
<br />
<br />
<div class="aboutpara"><img src="http://simplifiedimpact.com/aboutus5.jpg" alt="** PLEASE DESCRIBE THIS IMAGE **" /><br />
Simplified Impact is a small web design company based in Cork, Ireland.</div>
</div>';document.write(code);
</script>
Why isn't this working? - I want the whole div + other stuff to disappear when it's disabled, not just the button - I always phrase thinks wrong!
Thanks,
Ed
|
|
|
December 23rd, 2007, 05:31 PM
|
#7
|
|
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 29
Posts: 1,107
Thanks: 0
Thanked 0 Times in 0 Posts
|
Re: Showing something on a page - only if they have Javasciprt disabled.
So what you want is <yesscript>. This does not exist, but it's easily faked via CSS.
Wherever you would like <yesscript>, put <div class="yesscript">. Wherever you would like </yesscript>, put </div>.
In your CSS, apply .yesscript { display: none }.
Then run the following javascript :
Code:
function yesScript() {
var x = document.getElementsByTagName("div")
for (i=0;i<x.length;i++) {
if (x[i].className == "yesscript") { x[i].style.display = "block" }
}
This will not have the desired result for browsers that ignore CSS, but that's a tiny fraction of users and you can still explain what's going on to them.
Last edited by MikeHopley; December 23rd, 2007 at 05:37 PM..
|
|
|
December 23rd, 2007, 05:39 PM
|
#8
|
|
Highly Reputable Member
Join Date: Jul 2007
Location: Cork, Ireland
Posts: 828
Thanks: 1
Thanked 2 Times in 2 Posts
Rep Altering Power: 0
|
Re: Showing something on a page - only if they have Javasciprt disabled.
|
|
|
December 23rd, 2007, 05:51 PM
|
#9
|
|
Most Reputable Member
Join Date: Oct 2007
Location: UK
Posts: 1,633
Thanks: 22
Thanked 84 Times in 79 Posts
Rep Altering Power: 0
|
Re: Showing something on a page - only if they have Javasciprt disabled.
You need to use
Code:
<script type="text/javacript">
instead of
|
|
|
December 23rd, 2007, 05:52 PM
|
#10
|
|
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 29
Posts: 1,107
Thanks: 0
Thanked 0 Times in 0 Posts
|
Re: Showing something on a page - only if they have Javasciprt disabled.
I would put all your javascript in an external file.
I even remove my inline event handlers. 
|
|
|
December 23rd, 2007, 07:00 PM
|
#11
|
|
Highly Reputable Member
Join Date: Jul 2007
Location: Cork, Ireland
Posts: 828
Thanks: 1
Thanked 2 Times in 2 Posts
Rep Altering Power: 0
|
Re: Showing something on a page - only if they have Javasciprt disabled.
I'm still having problems. :(
|
|
|
December 23rd, 2007, 07:13 PM
|
#12
|
|
Highly Reputable Member
Join Date: Sep 2007
Age: 17
Posts: 716
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Re: Showing something on a page - only if they have Javasciprt disabled.
Yeah, this is weird! Mike's script should work, but it doesn't. Odd...
|
|
|
December 24th, 2007, 06:26 AM
|
#13
|
|
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 29
Posts: 1,107
Thanks: 0
Thanked 0 Times in 0 Posts
|
Re: Showing something on a page - only if they have Javasciprt disabled.
Um...
I missed out a closing } at the end of the function.
Can you check the JS with Firebug or a JS error console?
|
|
|
December 24th, 2007, 09:29 AM
|
#14
|
|
Highly Reputable Member
Join Date: Jul 2007
Location: Cork, Ireland
Posts: 828
Thanks: 1
Thanked 2 Times in 2 Posts
Rep Altering Power: 0
|
Re: Showing something on a page - only if they have Javasciprt disabled.
I get:
Quote:
|
Originally Posted by Firebug
x is not defined
|
Code:
for (i=0;i<x.length;i++) {
What does this mean?
Last edited by Ed; December 24th, 2007 at 09:53 AM..
|
|
|
December 24th, 2007, 10:46 AM
|
#15
|
|
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 29
Posts: 1,107
Thanks: 0
Thanked 0 Times in 0 Posts
|
Re: Showing something on a page - only if they have Javasciprt disabled.
Your code is slightly mistyped. Here's what you have:
Code:
function yesScript() {
var x = document.getElementsByTagName("div") }
for (i=0;i<x.length;i++) {
if (x[i].className == "yesscript") { x[i].style.display = "block" }
}
You should have:
Code:
function yesScript() {
var x = document.getElementsByTagName("div")
for (i=0;i<x.length;i++) {
if (x[i].className == "yesscript") { x[i].style.display = "block" }
}
}
"x" is an array holding all the <div> tags in the document. The "for" loop cycles through these, using the index of "i". "x[i]" is the i-th <div> in the document (well, actually the (i+1)-th <div>, because numbering starts at 0).
Each of these is checked for the className. If the className matches, the style is rewritten.
|
|
|
December 24th, 2007, 10:57 AM
|
#16
|
|
Highly Reputable Member
Join Date: Jul 2007
Location: Cork, Ireland
Posts: 828
Thanks: 1
Thanked 2 Times in 2 Posts
Rep Altering Power: 0
|
Re: Showing something on a page - only if they have Javasciprt disabled.
Oh, it's still not working! This really bugs me as I hate nagging all the time. Fix this, Fix that... Are there any other methods? If not, why wouldn't this be working? Apologies, Ed
|
|
|
December 24th, 2007, 11:35 AM
|
#17
|
|
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 29
Posts: 1,107
Thanks: 0
Thanked 0 Times in 0 Posts
|
Re: Showing something on a page - only if they have Javasciprt disabled.
Quote:
Originally Posted by Vivara
Oh, it's still not working! This really bugs me as I hate nagging all the time. Fix this, Fix that... Are there any other methods? If not, why wouldn't this be working? Apologies, Ed
|
Oh dear.  Sorry, I thought that would be a straightforward solution. I use something similar on my site, and it seems to work fine.
Your problem now is not this specific script, but rather your method of including JS at all. Check your HTML validation: it's interpreting the JS as HTML, which means that obviously something's badly wrong with your placement of the script.
It's been a long time since I used any internal JS, but I think you may need some special comment characters around your script. Look up the basics of including JS on a webpage.
Alternatively, take it out into an external file again.
|
|
|
December 24th, 2007, 12:02 PM
|
#18
|
|
Highly Reputable Member
Join Date: Jul 2007
Location: Cork, Ireland
Posts: 828
Thanks: 1
Thanked 2 Times in 2 Posts
Rep Altering Power: 0
|
Re: Showing something on a page - only if they have Javasciprt disabled.
Oh Dear indeed.
My method of including JavaScript was fine - I've used this many times before (and the validator says it's cool too).
However, I have moved it to an external file.
I just wanted to check with you that all I have to do in the external file is paste the code, no start tags or anything?
Looks like I'll have to figure some other way - this doesn't look like it's going to work.
What about the way swagner first mentioned, what's wrong with that?
Thanks,
Ed
|
|
|
December 24th, 2007, 12:13 PM
|
#19
|
|
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 29
Posts: 1,107
Thanks: 0
Thanked 0 Times in 0 Posts
|
Re: Showing something on a page - only if they have Javasciprt disabled.
Quote:
Originally Posted by Vivara
My method of including JavaScript was fine - I've used this many times before (and the validator says it's cool too).
|
Interesting. HTML Validator for Firefox gave me parsing errors. That's probably because it applies two layers of validation, whereas the W3C validator only applies one.
Quote:
|
I just wanted to check with you that all I have to do in the external file is paste the code, no start tags or anything?
|
That's right. An external file is only the javascript -- no HTML whatsoever (just like external CSS).
Quote:
|
What about the way swagner first mentioned, what's wrong with that?
|
Nothing, except for the problems associated with document.write: it's not allowed in XHTML, and it's buggy in Gecko browsers such as Firefox. Since you're not using XHTML, the former is irrelevant here.
But this would be a fine solution; in fact, it's arguably better than mine because it does not rely on CSS.
If you want to avoid the problems with document.write, you'll need to use DOM methods instead (longer and slower, but safer).
Last edited by MikeHopley; December 24th, 2007 at 12:18 PM..
|
|
|
December 24th, 2007, 12:21 PM
|
#20
|
|
Most Reputable Member
Join Date: May 2007
Location: UK
Age: 29
Posts: 1,107
Thanks: 0
Thanked 0 Times in 0 Posts
|
Re: Showing something on a page - only if they have Javasciprt disabled.
Quote:
Originally Posted by Vivara
I am using XHTML, I switched...lol.
|
No you're not. You just think you are! I love the Socratic method.
This line of code entails that you are not using XHTML:
Code:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Browsers will interpret your code as HTML, and therefore you can use document.write if you wish.
Alternatively, read up on DOM methods.
Last edited by MikeHopley; December 24th, 2007 at 12:24 PM..
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|