Author |
Message |
killing-hours
RavenNuke(tm) Development Team

Joined: Oct 01, 2010
Posts: 438
Location: Houston, Tx
|
Posted:
Fri Oct 29, 2010 12:03 pm |
|
!! ORIGINAL POST REMOVED !!
----------------------------
Sorry to edit this topic, however, the first approach at this was highly incorrect. The markup was completely backwards and it would never pass validation.
----------------------------
Source:
(http://stackoverflow.com/questions/2918970/how-to-show-hidden-div-when-javascript-is-disabled)
instead of a class, give your error message an ID attribute.
Example:
Code:echo '<div id="jsFail" align="center">Javascript Failure';
echo '<br /><br />In order to use this feature, you must have javascript enabled. Please enable javascript to remove this message. If your browser does not support javascript, download any of the <u>FREE</u> browsers that do.';
echo '<br /><br />Firefox - http://www.firefox.com<br />Internet Explorer - http://www.windows.microsoft.com/ie<br />Opera - http://www.opera.com/download/<br />Google chrome - http://www.google.com/chrome</div>';
|
Then in your JAVASCRIPT (not within the jquery "document ready") add this.
Code:document.write('<style type="text/css" media="screen"> #jsFail { display: none; }</style>');
|
--------------------
I essence... what you're doing is SHOWING the error message... and using javascript (NOT JQUERY) to hide the element.
Sample code:
Code:document.write('<style type="text/css" media="screen"> #jsFail { display: none; }</style>');
$(document).ready(function() {
//// Jquery here ////
});
|
|
_________________ Money is the measurement of time - Me
"You can all go to hell…I’m going to Texas" -Davy Crockett
Last edited by killing-hours on Tue Jul 05, 2011 2:28 pm; edited 3 times in total |
|
|
 |
Raven
Site Admin/Owner

Joined: Aug 27, 2002
Posts: 17088
|
Posted:
Sun Oct 31, 2010 10:51 am |
|
Nice. Thanks for sharing! I have made this a STICKY  |
|
|
|
 |
killing-hours

|
Posted:
Sun Oct 31, 2010 11:25 am |
|
Thanks raven. Hope others get use from it. |
|
|
|
 |
killing-hours

|
Posted:
Fri Nov 05, 2010 11:16 am |
|
Palbin/Raven or anyone who might know...
Is it possible to use this code to prevent entire site from loading if JS fails through the addons folder somehow? |
|
|
|
 |
Palbin
Site Admin

Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania
|
Posted:
Fri Nov 05, 2010 12:57 pm |
|
I think this would work. Make a file called something like head-jscheck.php and place it in the includes/addons folder. Then for code do something like:
Code:
if (HOW EVER YOU CHECK FOR JS) {
DISPLAY YOUR MESSAGE HERE
die();
}
Make sure to include the die as that is what is going to stop the site from displaying. There are better ways to do this like by editing header.php, but that would require you to edit core files. I am not a search engine guru like some of the other guys here, but if you do this I do not think your site will be indexed by Google or any other search engine.
|
|
_________________ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. |
|
|
 |
killing-hours

|
Posted:
Fri Nov 05, 2010 1:55 pm |
|
Hrm... that could create a problem. I'll come up with a better way to add some sort of notification site wide if JS fails instead of preventing the entire site from not being shown. I see what you mean by not being indexed now that you mention it. Thanks! |
|
|
|
 |
spasticdonkey
RavenNuke(tm) Development Team

Joined: Dec 02, 2006
Posts: 1693
Location: Texas, USA
|
Posted:
Fri Nov 05, 2010 2:24 pm |
|
One thing to keep in mind is google will index the contents of noscript tags, so if you are concerned about SEO be careful what you put there. Especially at the top of the page. |
|
|
|
 |
killing-hours

|
Posted:
Fri Nov 05, 2010 3:16 pm |
|
Alrighty then... how bout this one.
Instead of disabling the site... how about having the no script redirect the end user to a regular html page with instructions listed above?
Will that also send the crawlers to the redirect as well or will they see through that?
(I'm not so savvy when it comes to SEO) |
|
|
|
 |
spasticdonkey

|
Posted:
Fri Nov 05, 2010 3:57 pm |
|
What I would probably do is to set a cookie by javascript, then check for it via php. If no cookie, then display a short message with a link to a page with your more detailed message. Or even put that short message in an image, as google can't read that. This requires jquery cookie, but something like:
Code: if (!isset($_COOKIE["yourcookie"]))
{
echo = '<script type="text/javascript">
$.cookie("yourcookie", "somevalue");
</script>';
// a message that displays once
echo = '<noscript><a href="YOUR_WARNING_PAGE" rel="nofollow"><img src="YOUR_WARNING_IMAGE"/></a></noscript>';
}
|
So if you use that code on every page load, it will only display once if they have cookies enabled. So you can make it extra bright and annoying, lol. I can't really say how the googlebot deals with cookies, but some alternative such as this is the best you will get from an SEO perspective. @ least your warning only gets indexed once and not on every page.. alos notice the rel="nofollow" telling search engine not to follow that link
EDIT:
or wait, I guess it would always display if JS is disabled, but at least that section of code would only run once if JS is enabled, and if you can find that cookie later you know the user has both cookies AND js enabled |
|
|
|
 |
killing-hours

|
Posted:
Fri Nov 05, 2010 4:52 pm |
|
Hold on a min there.... you lost me @ "What I would probably do is to set a cookie by javascript". That seems a bit backwards to me.
Here's the flow of things so you can kinda understand why I'm digging into this.
Our site is "mostly" protected. Within the protected area are my forms which have the "no scripts" in them in case the end user doesn't have JS enabled... the forms don't display to them and the no script applies. I'm not so much worried about the bots on those pages as they are restricted anyhow.
Where I'm wanting to "notify" or at the very least redirect... is in the instance an end user hits the index page with JS disabled... they automatically get sent or notified somehow that there JS is disabled/blocked and that the site will NOT render correctly. (So I don't have to answer this stupid question over and over again by phone)
Again, I'm not very SEO savvy so I don't really understand how it all works or the best practices etc... but I do understand that google/yahoo/etc have crawlers/bots/whatever that index the net.
So the problem arises... how do I notify the end user that they have JS disabled without jacking them around to much and also at the same time leaving the site enabled for bots?
One thing I thought of on the way home is just having a plain jane message box appear with the no script as it shouldn't mess with the bots (I hope) but it will annoy the heck out of the end user.
Thanks for taking the time to help me through this. |
|
|
|
 |
spasticdonkey

|
Posted:
Fri Nov 05, 2010 5:16 pm |
|
well when i was suggesting setting a cookie by js, it was kinda a backwards way to detect if JS is enabled.. but if cookies are disabled too, maybe that's not the right solution. You need to detect this for every visitor? or registered users that might actually use the form(s)?
I'm pretty sure you have to enable JS to register, but I could be wrong, or you could be creating accts for people. thinking out loud... does your site break horribly with JS disabled? |
|
|
|
 |
killing-hours

|
Posted:
Fri Nov 05, 2010 7:55 pm |
|
Nosir.... actually... I'm just trying to annoy those end users who haven't registered but come to the site with JS disabled with a message or something explaining why the page is all jacked up. That's all.
Reason being... my end users are no where close to "tech savvy" and they tend not to read anything no matter how big & bold it is. They would rather pick up the phone and call me and have me waste my precious time trying to figure out what is wrong with their machine or blame it on me rather than take the time to try and figure it out on their own or take the blame themselves.
The forms I'm not worried about in the least... they are behind registration + the no script so that part is all good.
----------------
edit***
To better illustrate... I disabled JS and went to nukens site and this is what happens to his content slider.
So as a way to explain to end user "why" this is happening (rather by message than phone) I'm trying to come up with a way of doing that for them as well as keep the search engines happy. |
|
|
|
 |
nuken
RavenNuke(tm) Development Team

Joined: Mar 11, 2007
Posts: 2024
Location: North Carolina
|
Posted:
Sat Nov 06, 2010 7:16 am |
|
How about using a noscript tag with a meta refresh to redirect to a page explaining what they need? Or include a page above the header?
Edit: Or include the good crawlers into an array http://www.cult-f.net/detect-crawlers-with-php/ |
_________________ Only registered users can see links on this board! Get registered or login! |
|
|
 |
killing-hours

|
Posted:
Sat Nov 06, 2010 9:22 am |
|
That's what I was thinking with the redirect. Use a no script to shuffle them off to a page explaining what is going on etc. What I don't know about that option... is if it will loop the bots over and over again to that page thus bypassing the actual site.
the "good crawler" code will ultimately be a real pain in the butt IMO. If you were to use that code... A) You would have to find as many crawlers as possible B) you would have continually check the code to ensure that it's up to date. It's a great suggestion... but I believe in the long run... it will cause more work for the admin.
Just my .02 |
|
|
|
 |
spasticdonkey

|
Posted:
Sat Nov 06, 2010 3:56 pm |
|
ya it's a tough question, and I understand why you want this, but all methods you could possibly use have their drawbacks. Although you may be able to get some sort of meta refresh inside a noscript tag to work, it's not compliant and may cause other issues.. noscript should not appear in the head element, meta cannot appear in the body element, and meta should not appear in the noscript element.
starting to run out of ideas, but...
You might look at theme CT_RN that displays a yellow bar across the theme if you are anonymous, with a registration message. Maybe you could do something similar with a noscript tag in your theme.?
or this is another backwards way:
Code:<p id="noscript">You have JavaScript disabled. That's why half the internet is broken. Quit calling tech support :)</p>
<script type="text/javascript">document.getElementById('noscript').display = 'none';</script>
|
|
|
|
|
 |
killing-hours

|
Posted:
Sat Nov 06, 2010 6:06 pm |
|
This may ultimately end up being one of those things that is just unavoidable. The only alternative that I can possibly see is having a plain jane message box show up using a no script. I'll mess around with that some other day.
Thanks for the conversation guys. |
|
|
|
 |
killing-hours

|
Posted:
Thu Apr 14, 2011 6:23 pm |
|
Original post updated. Sorry for leading you astray. |
|
|
|
 |
Guardian2003
Site Admin

Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam
|
Posted:
Fri Apr 15, 2011 3:13 am |
|
|
|
 |
killing-hours

|
Posted:
Fri Apr 15, 2011 3:50 am |
|
updated first post with this response. |
|
|
|
 |
|