Access the -Webkit- Vendor Prefix in JavaScript

How to get a list of valid values for a CSS property with javascript?

I know your question is asking for a way to check valid values for vendor specific cursors (and, potentially, other CSS properties), but if all you are looking for is a cross-browser solution for styling cursors, you might just want to use your own images for the cursors in question.

http://www.google.com/intl/en_ALL/mapfiles/closedhand.cur
http://www.google.com/intl/en_ALL/mapfiles/openhand.cur

For example, you could use:

document.getElementById('foo').style.cursor = "url(/closedhand.cur) 4 4";

You might even wish to use this in conjunction with a check to see if known properties are valid, for example:

if( window.CSS.supports('cursor','grab') )
{
cursor = 'grab';
}
else if( window.CSS.supports('cursor', '-moz-grab') )
{
cursor = '-moz-grab';
}
else
{
cursor = 'url(/grab.cur)';
}
document.getElementById('foo').style.cursor = cursor;

You could easily extend this to test all of the popular vendor prefixes, then only apply this logic to the properties with which you know have limited browser support.

CSS.supports API Browser Compatibility

CSS.supports MDN

how to get the base url in javascript

Base URL in JavaScript

You can access the current url quite easily in JavaScript with window.location

You have access to the segments of that URL via this locations object. For example:

// This article:
// https://stackoverflow.com/questions/21246818/how-to-get-the-base-url-in-javascript

var base_url = window.location.origin;
// "http://stackoverflow.com"

var host = window.location.host;
// stackoverflow.com

var pathArray = window.location.pathname.split( '/' );
// ["", "questions", "21246818", "how-to-get-the-base-url-in-javascript"]

In Chrome Dev Tools, you can simply enter window.location in your console and it will return all of the available properties.


Further reading is available on this Stack Overflow thread

How to get element class by prefix via jQuery

Try this:

JavaScript

$("div").each(function(index, elem){
var classes = $(elem).attr("class");
var color = classes.replace(/.*cc-colour-([^\s]+).*/g, "$1");
var size = classes.replace(/.*cc-size-([^\s]+).*/g, "$1");
var width = classes.replace(/.*cc-width-([^\s]+).*/g, "$1");
console.log(color, size, width); //red big narrow, blue small wide, green medium narrow
});

HTML

<div class="cc-colour-red cc-size-big cc-width-narrow">
<div class="cc-colour-blue cc-size-small cc-width-wide">
<div class="cc-colour-green cc-size-medium cc-width-narrow">

jQuery - Get a element class based on a prefix

var classes = $('.MyElement').attr('class').split(' ');
for (var i = 0; i < classes.length; i++) {
var matches = /^fx\-(.+)/.exec(classes[i]);
if (matches != null) {
var fxclass = matches[1];
}
}

How To Adjust A Value In CSS from JavaScript?

You can use the style property to access the styles of the selected element (there's multiple other ways check: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style for more information). Also you can't chain selectors with document.getElementById, you can definitely do that with jQuery though.

var b = document.getElementsByClassName("pic-hover");
b[0].style.left = "800px";

Loading local file in browser referenced css or js

That's happening becuause you have <base> tag.

The base URL to be used throughout the document for relative URL addresses. 

Since the base URL href is '/', it always start from root. So on local machine it doesn't find any css/js files, as it would check the files from root i.e. C/D/E drive. And it totally works fine for webserver, since the root would be your public folder.

Get rid of base tag.

HTML5 - Access Camera

You are missing errorCallback function.

function errorCallback(e) {
console.log(e);
}

I added this and got an error:
Sample Image

To access userMedia you have to have https. I tried running it here (jsfiddle) and works for me.



Related Topics



Leave a reply



Submit