JavaScript enabling on browser when a button is clicked (not automatically) - javascript

I use a lot of JavaScript on my site (currently under construction). My worry is if some of the client side's system has JavaScript disabled then my site will "miserably fail".
I know that we cannot programatically override to enable JavaScript as it would be a security issue. But what I want is if the client side system has JavaScript disabled then a popup should appear with a button so that when the user clicks the button automatically JS will be enabled no matter in what browser he is viewing the site.
I am asking this because I saw the same thing myself when I viewed some other site.

That is not possible. You can however display instructions on the page on how to enable JavaScript, but considering that people who disable JavaScript usually know what they are doing they'll know how to enable it themselves.
I'd say there are very few people who accidentally disable JavaScript, so your worries are probably unnecessary.

Well if you want a popup to appear then you need to make it happen using javascript, so I guess the answer is that you can just ignore the very small percentage of people who have javascript disabled for their browsers.

What you are probably looking for is Progressive enhancement.
Instead of showing a message through JavaScript that tells the user to enable JavaScript you do it the other way around.
By default you show a message, in a div for example, and when JavaScript is enabled you hide the div. You only use JavaScript to enhance the user experience but offer a 'reasonable' experience when the user doesn't have JavaScript enabled. Reasonable could mean in your case an empty page with some text that explains why you really need JavaScript.

Related

How to disable the whole navigation bar using javascript on pageload in any browsers

Hi I am trying to figure out if there is any way to disable the browser navigation bar so that the user is not able to reload the url or unable to the click on browser reload . I tried to find the solution but I could only see like this below in most of the sites .
window.open('URL', 'null', 'width=900,height=750,toolbar=no,scrollbars=no,location=no,resizable =no');
window.moveTo(0, 0);
I am trying to find the solution using Java Script or JQuery and learn in the process. In my application after the first page and after click on submit button then the second page is OTP page and I want to not show the navigation bar or not to allow the user to reload the page while entering the OTP . I am hardly find the solution and any help would be appreciated.
Most of the browsers dont have that feature or has that feature but not turned on due to user experience concerns. It could be easily exploited by hackers so its usually not possible for safety concerns

Web extension - alternative to notification with button

I have a web extension that lets any website access the clipboard. On request I will ask the user if it is okay to give access to the clipboard.
I do this in two ways
I create a notification
The problem: firefox doesn't allow buttons, so in the message I say "Click here to allow website x access". I added an eventlistener to the notification that sends a message back to the content script and it proceeds from there. It's okay but not really the best solution (I want buttons)
As a fallback I have a simple confirm box.
The problem: it doesn't really look good.
Now my other idea is to create a custom confirm box. That means create some html, css and javascript and append it to the DOM. This although is potentionally dangerous as websites can just trigger a "click" on the "allow access"-button then.
So I am basically looking for a nice and safe way to get confirmation from the user.
So what next? iframes? Is it possible to include an html page from the addon with access to a content script in an iframe?
Or is there some other way I can implement this maybe web extensions already offer something like this?
Completely overlooked the click event argument. There is a event.isTrusted property which is false when the event was triggered. (maybe not available in all browsers). But this pretty much solves the issue.

How to disable the execution of JavaScript in a simple way?

I want to measure the HTML parsing time of some webpages. One difficulty is the parsing and JavaScript execution happen alternatively.
I am not familiar with html and javascript, is there any simple way to disable the execution of the scripts?
E.g. inserting <noscript> to some places (I am not sure if this will work)
By the way, I do experiments on Android.
You can disable JavaScript in Chrome developer tools. Click on settings icon on lower right of the tool then you will find the settings.
Type
chrome://settings/content
in Chrome browser address bar.
Under JavaScript section select "Do not allow any site to run JavaScript".
Click Done.
Refresh page, JavaScript will not be executed.

How do I detect the client has javascript turned on/off from Rails?

I don't want to deal with users who have javascript turned off, so I want to just prevent them from using my application. I want to detect if the user has javascript turned on so I can redirect them to a page that tells them they need to use javascript. I'm sure its in the request header. Anyone have any ideas how I can do this?
The noscript tag is the easiest solution, though not exactly whay you're looking for.
<noscript>Get outta here.</noscript>
Do you really need a redirect at all? Put the message in a <noscript> element, and it will only be displayed to those it applies to.
You can't. The server has no idea what the client has enabled. You can't even "detect" if Javascript is disabled from the client (because what would you use to do so?).
You can use tricks to show content when Javascript is disabled (for instance, a <noscript> tag, or using Javascript to hide content that is meant for JS-only).
There is no way to detect JavaScript on the server side. However, you can use a NOSCRIPT tag to display a message indicating that your website requires JavaScript.
For an example, turn JavaScript off in your browser and load a Stack Overflow page. There'll be an obnoxious red message across the top of the page warning you that the site works best with JavaScript enabled. You can examine the Stack Overflow source code and CSS styling to see how they implemented it.
If you really want to deter non-JavaScript users from using your website, you could put your message in a div inside the noscript tag and expand the div to cover everything on the page.
You only need html:
<noscript><meta http-equiv="refresh" content="0;url=http://example.com/use_js.html" /></noscript>
This of course won't prevent the server from serving content, it only will output this meta refresh tag, which will be parsed (and executed by redirecting the user) by clients that got no javascript or javascript disabled.
You could have a landing page with a snippet of javascript that runs and redirects to the real railsy landing page, or perform an AJAXY call to get the data you want to show the user. This would positively require javascript to be enabled to continue.

add bookmark in Firefox without any dialog box

Using JavaScript, is it possible to add a bookmark in Firefox directly, without opening any dialog box? That is, I want the user clic on a link and that the bookmark is automatically created, without the need to any further step.
Fortunately, no. It would be a horrible breach of security.
Could be a different story in the context of a Firefox Extension, but I assume you are asking for a normal web page.
If it was possible, any possible website would be able to create any kind bookmark, without the user even noticing.
As a user, I certainly hope this is not possible ^^
(And, as a developper, I don't think it is)

Categories