Is it possible to check if cookies are enabled with modernizr? - browser

I was researching about how to check if the cookies are enabled in a browser and i found a lot of answer, i even tested a few ones, but after that a friend of mine suggest me to use Modernizr for that.
I started to search about that and i found a lot of stuff related with CSS3 and HTML5, but i don't want that, i just wanna know if is it possible to check that cookies are enabled or not with Modernizr?

check this url, hope it's helpful :
https://github.com/Modernizr/Modernizr/commit/33f00fbbeb12e92bf24711ea386e722cce6f60cc

Below code is copied from http://sveinbjorn.org/cookiecheck.
function are_cookies_enabled()
{
var cookieEnabled = (navigator.cookieEnabled) ? true : false;
if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled)
{
document.cookie="testcookie";
cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
}
return (cookieEnabled);
}

A direct answer to the question is 'Yes!' and it is built in
Example code:
if (Modernizr.cookies == false) {
alert('Please enable cookies');
}
else {
// do something with cookies
}
You can also use the css class .cookies or .no-cookies to show/hide a panel telling the user they need cookies enabled.
.cookies #noCookies
{
display: none;
}
<div id='#noCookies'>
This site requires cookies! Please turn them on already!
</div>
(This .cookies class is added to <body> tag by Modernizr).
Note: If you are creating a custom build of Modernizr the cookies option is currently 'hidden' under the 'Non-core detects' section.

Another way with PHP
HTML/PHP:
<?php
session_start();
$_SESSION['cook'] = 1;
echo "<img src=\"cookcheck.php\">";
?>
PHP - cookcheck.php:
<?php
session_start();
if ($_SESSION['cook'] !== 1)
{ $image="/nocookmsg.png"; } # Cookies NOT Enabled
else { $image="/blank.png"; } # Cookies Enabled
$img=imageCreateFromPNG($image); # Create Image
header("Content-type: image/png"); # Send Header
imagePNG($image); # Send Image
?>

Related

Why won't custom WordPress page load get_posts array data?

I've got 3 separate files.
Forms (a basic wordpress page built within Wordpress). The data here shows up fine and works as expected.
<div class="select-wrapper">
<select class="paybill" name="provider-name" id="provider-name" onchange="formFilter(this.value)">
<option value="" disabled selected hidden>- Choose a Provider -</option>
<?php foreach( $providerslist as $providerlist ) {
$theprovidernname = get_the_title($providerlist);
$providerlocations = get_field('provider_locations', $providerlist);
$pcount = count($providerlocations);
for($i = 0; $i < $pcount; $i++){
$location_name = get_field_object('location_name', $providerlocations[$i]);
if(!empty($location_name)){
break;
}
}
if(empty($location_name)){
$location_name = array(value=>"TEXT");
}?>
<option value="<?php echo $location_name['value']?>"><?php echo $theprovidernname; ?></option>
<?php } ?>
</select>
</div>
A filtering Javascript file. The purpose of this file is to get the data from the select field and pass it using AJAX to the 3rd PHP file.
function formFilter(str){
//clears previous results
document.getElementById("form-results").innerHTML = "";
var value = str.value;
console.log(value);
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
var xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
document.getElementById("form-results").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET",".../framework-forms-results.php?location="+value,true);
xmlhttp.send();
}
A custom PHP file living in the Child Theme folder of the site. What I'm trying to do is call a custom post type called 'location' and then work through the data. On other pages I'm able to get this exact code to work just fine but here it will not work at all. This is the entirety of this Page at the moment. If I remove the get_posts code and just echo some text, it will return the text so I know the issue is with the get_posts call. I just can't figure out why. If I try to load this page alone without going through the select options, it still returns a 500 error.
//Create Array of All Locations
$locations = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'location',
));
print "<pre>";
print_r($locations);
print "</pre>";
Any thoughts as to why the get_posts call won't work on this custom page but will work if it's used via shortcodes on pages built within wordpress?
I've tried debugging, logging errors and reviewing the logs. I've tried to require the blog header to bring in other necessary files but nothing.
If you are calling this URL directly, which is not how WordPress ajax is intended to work, you can still get this code to run by adding this PHP code:
$parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
require_once( $parse_uri[0] . 'wp-load.php' ); to the top of the file.
Link: https://codex.wordpress.org/AJAX_in_Plugins (I know this says Ajax in plugins but this is also what you would do if developing a custom theme to keep your code WordPress-y).

Exclude Externals from jsDoc output

How can we exclude Externals section from jsDoc output correctly?
I have lots of externals in my project that I do not want to show on the navigation panel at all, as it takes up all the space, and is useless to us.
I have been able to hack it manually, by changing the code in file node_modules\jsdoc\lib\util\templateHelper.js, but this is not a reusable approach for my team of developers.
The hack was in overriding members.externals with an empty array:
/*
members.externals = members.externals.map(function(doclet) {
doclet.name = doclet.name.replace(/(^"|"$)/g, '');
return doclet;
});
*/
members.externals = [];
Unfortunately, after years of using jsDoc, all I can do is to continue re-hacking it after every update of the dependency, in file node_modules\jsdoc\lib\util\templateHelper.js.
Fortunately, even with the current version 3.5.5, the hack still works the same:
// HACK: set Externals to an empty list:
members.externals = []; /*members.externals.map(function(doclet) {
doclet.name = doclet.name.replace(/(^"|"$)/g, '');
return doclet;
});*/
I'm not sure this is much more elegant, but this is what I ended up doing. It works for all projects without having to hack the jsdoc install.
My problem: I have classes derived from imported node_modules and I wanted the inherited information included in my documentation, but I didn't want the base classes clogging up the sidebar navigation.
First, I added a plugin to my jsdoc-template (I called it skip-node_modules):
exports.handlers = {
processingComplete: function (e)
{
for (let i = 0; i < e.doclets.length; i++)
{
const doclet = e.doclets[i]
if (!doclet.undocumented && doclet.meta && doclet.meta.path.indexOf('node_modules') !== -1)
{
// hack the name so I can find it in the .tmpl file
// I tried to add a new flag to the doclet, but it didn't pass through
doclet.longname += '~'
}
}
}
};
Then I added a check in the navigation.tmpl:
<ul class="list">
<?js
this.nav.forEach(function (item) {
?>
<?js if (item.longname[item.longname.length - 1] !== '~') { ?>
<li class="item" data-name="<?js= item.longname ?>">
...
<? } ?>
And poof, no more node_module imports in my sidebar. (This does have the downside of not showing a sidebar when you click through to these classes. I'm sure with more hacking I can get rid of that, but it wasn't too important.)
It would be easy to change this to check for external symbols. console.log(e) in the plugin to get all the info the doclets provide and find what works for your situation.

google extension inline install and Verified not working

google.com/webstore i have add my extension
i Have check "This item uses inline install."
Websites: chose Verify site
google.com/webmasters i have add site and Verifyed.
when i put this code on me site:
<link rel="chrome-webstore-item"href="https://chrome.google.com/webstore/detail/itemID">
<button onclick="chrome.webstore.install()" id="install-button">Add to Chrome</button>
<script>
if (document.getElementById('extension-is-installed')) {
document.getElementById('install-button').style.display = 'none';
}
</script>
i click on button "Add to Chrome" install app extension, but when i refresh site button "Add to Chrome" is display. why? i cant Understanding
You're obviously following the guide at https://developer.chrome.com/webstore/inline_installation
In that case, you missed a step.. Let's look at the code.
if (document.getElementById('extension-is-installed')) {
document.getElementById('install-button').style.display = 'none';
}
The condition here is whether an element with ID extension-is-installed is present on the page. But what adds it?
A step back:
For example, you could have a content script that targets the installation page:
var isInstalledNode = document.createElement('div');
isInstalledNode.id = 'extension-is-installed';
document.body.appendChild(isInstalledNode);
So, you need to add a Content Script that adds that element to the page.
However, I doubt that guide will work. By default, content scripts execute after DOM is loaded (and therefore, that hiding script has executed). You can make them run at document_start, but then body does not exist yet.
Let me make an alternative hiding script, based on communicating with the extension using "externally_connectable". Suppose your website is example.com, and your extension's ID is itemID
Add example.com to sites you want to be messaged from:
"externally_connectable" : {
"matches" : [
"*://*.example.com/*"
]
},
In your background page, prepare for the message from the webpage:
chrome.runtime.onMessageExternal.addListener(
function(message, sender, sendResponse) {
if(message.areYouThere) sendResponse(true);
}
);
In your page at example.com, add a button (hidden by default) and code to show it when appropriate:
<button onclick="chrome.webstore.install()"
id="install-button" style="display:none;">
Add to Chrome
</button>
<script>
if (chrome) {
// The browser is Chrome, so we may need to show the button
if(chrome.runtime && chrome.runtime.sendMessage) {
// Some extension is ready to receive messages from us
// Test it:
chrome.runtime.sendMessage(
"itemID",
{areYouThere: true},
function(response) {
if(response) {
// Extension is already installed, keep hidden
} else {
// No positive answer - it wasn't our extension
document.getElementById('install-button').style.display = 'block';
}
}
);
} else {
// Extension is not installed, show button
document.getElementById('install-button').style.display = 'block';
}
}
</script>
Was requested to add page reload after install. chrome.webstore.install has a callback parameter specifically for this.
Instead of using onclick attribute, assign a function:
document.getElementById('install-button').addEventListener("click", function(e) {
chrome.webstore.install(function() {
// Installation successful
location.reload();
});
});

Avoiding Website content select and copy

I am using Drupal 6. In drupal how to avoid the user to copying the web page contents.How to disable it.
Thanks
Ultimately ... you can't.
Even if you try some fancy JavaScript or some fancy image over, etc., a user can just press Ctrl+A (select all) and then Ctrl+C (copy). There is a plethora of ways to get information from a web-site such as development environment (FireBug), alternative agents (wget/curl), or even using a browser not "protected" with the scheme.
Bottom line ... the only way to prevent someone from "keeping" that data is by not giving them access to begin with. Alternatively, make the user(s) sign an NDA/agreement and hire lawyers :-)
Happy doing productive things.
If all that is desired is prevent a "select" with a mouse, then an img-over may work. Alternatively, send back non-text (e.g. images containing the text) content and/or embed the content into Flash or another relatively controlled plug-in.
There is a java script code to disable the content copy.
I pasted that code into body of the page and set input format into php code.
<script type="text/javascript">
var donotconsidortag = ["input", "textarea", "select"]
donotconsidortag = donotconsidortag.join("|")
function unableToSelect(e) {
if (donotconsidortag.indexOf(e.target.tagName.toLowerCase()) == -1)
return false
}
function ableToSelect() {
return true
}
if (typeof document.onselectstart != "undefined")
document.onselectstart = new Function("return false")
else {
document.onmousedown = unableToSelect
document.onmouseup = ableToSelect
}
</script>
For the particular content type use " content template " module and past the above code in to content template's textarea.In this we can disable the content select option for whole content type(For ex:Page or Story)
<SCRIPT language=JavaScript>
var message = "function disabled";
function rtclickcheck(keyp){ if (navigator.appName == "Netscape" && keyp.which == 3){ alert(message); return false; }
if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) { alert(message); return false; } }
document.onmousedown = rtclickcheck;
</SCRIPT>
There is no way to prevent a determined user from accessing the content of your web page. Tools like firebug, and a plethora of screen capture software easily circumvent any such attempts.
To make it difficult for unsophisticated or lazy users, you could overlay a transparent 1x1 image over the top of the entire page, or content you are trying to protect.
<img src="transparent.png" style = "width:100%; height:100%;position:absolute;" />

Disable Specific Keys in IE 6

I need to disable specific keys (Ctrl and Backspace) in Internet Explorer 6. Is there a registry hack to do this. It has to be IE6. Thanks.
Long Edit:
#apandit: Whoops. I need to more specific about the backspace thing. When I say disable backspace, I mean disable the ability for Backspace to mimic the Back browser button. In IE, pressing Backspace when the focus is not in a text entry field is equivalent to pressing Back (browsing to the previous page).
As for the Ctrl key. There are some pages which have links which create new IE windows. I have the popup blocker turned on, which block this. But, Ctrl clicking result in the new window being launched.
This is for a kiosk application, which is currently a web based application. Clients do not have the funds at this time to make their site kiosk friendly. Things like URL filtering and disabling the URL entry field is already done.
Thanks.
For what purpose do you need this? Because disabling the backspace would be hell for typing urls or emails, etc.
We could recommend other workarounds if we knew the problem better.
EDIT 1:
This website seems to have some information as to how it's done. I can't verify it currently, but I'll look into it:
http://www.ozzu.com/programming-forum/disable-key-and-back-t44867.html
Edit 2:
This website has some key codes:
http://www.advscheduler.com/docs/manual/type_sendkeys.html
It seems BACKSPACE is 08.
EDIT 3:
Found some more code for blocking, check this out:
<script type="text/javascript">var sType = "keypress";</script>
<!--[if IE]>
<script type="text/javascript">sType = "keydown";</script>
<![endif]-->
<script type="text/javascript">
fIntercept = function(e) {
// alert(e.keyCode);
e = e || event.e;
if (e.keyCode == 116) {
// When F5 is pressed
fCancel(e);
} else if (e.ctrlKey && (e.keyCode == 0 || e.keyCode == 82)) {
// When ctrl is pressed with R
fCancel(e);
}
};
fCancel = function(e) {
if (e.preventDefault) {
e.stopPropagation();
e.preventDefault();
} else {
e.keyCode = 0;
e.returnValue = false;
e.cancelBubble = true;
}
return false;
};
fAddEvent = function(obj, type, fn) {
if (obj.addEventListener) {
obj.addEventListener(type, fn, false);
} else {
obj['e'+type+fn] = fn;
obj[type+fn] = function() {
obj['e'+type+fn](window.event);
}
obj.attachEvent('on'+type, obj[type+fn]);
}
};
fAddEvent(document, sType, fIntercept);
</script>
Ok, now you should have all you need to do it. To disable backspace, the keycode is 08. You can probably just use the code I posted with slight modifications only... :\
Try it out and see if it's what you needed. (I hope you know how to use Javascript.)
You can't do it from a web page. One of the main purposes of a web browser is to protect users from the internet. They define a very specific set of things that web sites can do, and disabling buttons isn't in the list.
On the other hand, if you're a network admin and just want to mess with your users, you might be able to do it via some desktop software. But I wouldn't hold my breath.
I'm using this jQuery solution (tested on ie6 and firefox 3.6):
$(document).keydown(function(e) {
var tag = e.target.tagName;
var ro = e.target.readOnly;
var type = e.target.type;
var tags = {
INPUT : '',
TEXTAREA : ''
};
if (e.keyCode == 8) {// backspace
if (!(tag in tags && !ro && /text/.test(type))) {
e.stopPropagation();
e.preventDefault();
}
}
});
hope it helps someone

Resources