Cómo garantizar que javascript en el navegador esté siempre habilitado mientras se navega por mi sitio plone

Yo deseo disable loading the plone site if JS is disabled in the browser. Where exactly do I change the code? Which template/skin do I choose? I want to ensure that JS is always enabled while browsing any part of the plone site. While browsing, if JS is disabled, I can redirect to another page with tag to enable the JS in the browser and give a hlink to the site back if it is enabled. I am using Plone 4.1

preguntado el 28 de agosto de 12 a las 08:08

3 Respuestas

There is no way to enable JS without the user doing it himself from the browser settings. You can add instructions on how to enable JavaScript or redirect to a page which has the instructions by using the noscript etiquetas como esta:

<noscript>
    <meta http-equiv="Refresh" content="5;url=http://example.com/foo/bar.php?js=false" />
</noscript>

Programas de meta tag redirects to your no JS page in 5 seconds to allow browsers to come to the current page by clicking the back button. If the time of the redirect is too little, the page may not be saved in the history de acuerdo con este artículo

Respondido 28 ago 12, 08:08

I suppose technically you should say "There is no way to enable JavaScript using JavaScript", though you could use a no-js CSS rule to show a message that instructs users to enable JavaScript (HTML5 Boilerplate has a good implementation of this) - Jason Sperske

@Amaan, The question is clear, I don't expect the JS to enable JS, I wish to disable loading the plone site if JS for the browser is disabled :) Please reply carefully - user956424

@user956424 "While browsing, if JS is disabled, I can redirect to another page with tag to enable the JS in the browser and.." You didn't say you were going to instruir them. You said you were going to habilitar JS. Anyway, I'll edit my answer to add how to do what you want. - Algún chico

@Amaan, I agree to the edited reply, but where in the plone site should I add this? which skin / template ? - user956424

@user956424 I don't really know since I've never used Plone. But with a little searching around, este looks like it should help you add the HTML to your page. - Algún chico

Are you willing to also require cookies? If so, one way to solve this is:

  1. Modify Plone's main template to include a test for a particular cookie.
  2. If that cookie is not found (test with template logic), show the "oops, you need js" content.
  3. In that no-cookie content section, include inline javascript to set a cookie and reload the page. If you don't want to allow js to set cookies, you can still set a query parameter on the redirect.
  4. If the cookie or query parameter is found, return the real content. If the query parameter, set the http-only cookie.

If you want to avoid cookies or other sessioning mechanisms, an alternative approach would be:

Modify Plone's main template to

  1. Set a display:none style on the visual portal or similar wrapper;
  2. Add a JavaScript-needed to view this page message with display style on;
  3. Put in inline JavaScript to set display:none on the JS-needed message and display:block on visual portal wrapper.

The gotcha on this is that the pages will actually be loaded w/o js — just not displayed. It's also certainly possible that the js-needed message might flash up while other resources load. Make sure the JS display fiddling is inline (not keyed to page ready or any other event) to minimize the effect.

Respondido 30 ago 12, 17:08

Is there any other option other than cookies? Thank you in advance. - user956424

If you can't use a cookie, you can't easily record the fact they have JavaScript available. That would mean redirecting on every page view. You could look into the sessions machinery and use fat URLs for session ID. - stevem

Your pages must be loaded by JavaScript, which replaces static page Please enable JavaScript in your browser. This is only way to solve the problem.

No tengo experiencia en Plone and don't know what template do that.

Respondido 28 ago 12, 22:08

that's exactly what I want to know were the code should go in for Plone :) - user956424

@user956424: Use a viewlet or customize the main_template. - Martijn Pieters

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.