CORS policy: No ‘Access-Control-Allow-Origin’

Font from origin domain.dev has been blocked… (CORS and browsersync)

If you are getting issue fonts are blocked in web client CORS then below code will help you. Use the code in .htaccess file and problem will be resolved 🙂
# Allow access from all domains for webfonts.
<IfModule mod_headers.c>
<FilesMatch “\.(ttf|ttc|otf|eot|woff|woff2|font.css|css)$”>
Header set Access-Control-Allow-Origin “*”
</FilesMatch>
</IfModule>

jQuery Sticky Navigation Effect

To create a sticky effect on the main navigation bar above when a user scrolls passed beyond it. Use below jquery code

jQuery(function(){
var menuOffset = jQuery(‘#site-navigation’)[0].offsetTop;
jQuery(document).bind(‘ready scroll’,function() {
var docScroll = jQuery(document).scrollTop();
if(docScroll >= menuOffset) {
jQuery(‘#site-navigation’).addClass(‘fixed’).css(‘width’,jQuery(‘#masthead’).width());
} else {
jQuery(‘#site-navigation’).removeClass(‘fixed’).removeAttr(“width”);
}
});
});

Fairly basic jQuery code. It will add a class to the navigation when a user scrolls beyond it. Only thing you’ll need to change here is the navigation selector, #site-navigation. Also, you may want to remove .css(‘width’,jQuery(‘#masthead’).width()). That part of the code is more specific to this site.

and include below css code in css file

#site-navigation.fixed{
position:fixed;
z-index: 9999;
top:0;
}

That’s done!!

Javascript Confirm Delete

How to use a javascript confirm box to ask the user if they want to delete

<script>
function confirmDelete(deleleteUrl) {
if (confirm(“Are you sure you want to delete”)) {
document.location = deleleteUrl;
}
}
</script>

<a href=”javascript:confirmDelete(‘delete.php?id=1’)”>Delete</a>

Another way

<a href=”delete.php?id=1″ onclick=”return confirm(‘Are you sure you want to delete?’)”>Delete</a>