All these years I've assumed that {zoom:100%;} and {height:1%;} where essentially the same, forcing an element to have layout (hasLayout property). After a very unproductive morning, being made to look foolish by IE7, I finally in desperation changed the zoom directive to height and my clear float hack started working. Note to self, go round the country and personally upgrade all IE6/7 versions to IE9!
Tuesday, 31 January 2012
IE7 and hasLayout
All these years I've assumed that {zoom:100%;} and {height:1%;} where essentially the same, forcing an element to have layout (hasLayout property). After a very unproductive morning, being made to look foolish by IE7, I finally in desperation changed the zoom directive to height and my clear float hack started working. Note to self, go round the country and personally upgrade all IE6/7 versions to IE9!
Sunday, 8 May 2011
Dynamcially adding style
Dynamically add style to a page...
Remember to minify the style text using something like http://refresh-sf.com/yui/
var style = "body{color:#666;}";
var s = document.createElement('style');
s.setAttribute("type", "text/css");
if (s.styleSheet) { // IE
s.styleSheet.cssText = style;
} else {
var stxt = document.createTextNode(style);
s.appendChild( stxt );
}
document.getElementsByTagName('head')[0].appendChild(s);
Remember to minify the style text using something like http://refresh-sf.com/yui/
Monday, 4 April 2011
'require': no such file to load -- sqlite3/sqlite3_native (LoadError)
When running "rails server" I was getting the following error...
'require': no such file to load -- sqlite3/sqlite3_native (LoadError)
Banging my head on the desk for ages with this one. Then realised the default Aptana workspace name contained white space chars! Remove these and all is fine.
Shame on me!
'require': no such file to load -- sqlite3/sqlite3_native (LoadError)
Banging my head on the desk for ages with this one. Then realised the default Aptana workspace name contained white space chars! Remove these and all is fine.
Shame on me!
Friday, 27 August 2010
Chrome extension, accessing extension variables from scripts

Just went all around the houses trying to access variables from a script running within a web page. In actual fact it's quite easy. You need two things, a background pages and an options page to administer your options. So the first thing you need to do is make sure you have a reference to background and options in your extention manifest...
...
"background_page": "background.html",
"options_page": "options.html",
...
From within your script you can then access variables using...
chrome.extension.sendRequest({action:"getItem",item:"somekey"}, function(response) {
var myvar = response.value
console.log("somekey:"+myvar);
});Background page should look something like this...
<html>
<head><title>background</title>
<script type="text/javascript">
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
switch(request.action){
case "clear" :
localStorage.clear();
sendResponse({message:"Thanks, localStorage has been cleared"});
break;
case "getItem" :
var value = localStorage.getItem(request.item);
sendResponse({value:value,message:"value returned from background.html"});
break;
case "getItems" :
var value = {};
for (var i=0;ivalue[request.items[i]] = localStorage.getItem(request.items[i])
}
sendResponse({value:value,message:"value returned from background.html"});
break;
case "setItem" :
localStorage.setItem(request.item,request.value);
sendResponse({message:"Thanks, your update has been saved"});
break;
case "setItems" :
for (name in request.items){
localStorage.setItem(name,request.items[name]);
}
sendResponse({message:"Thanks, your updates have been saved"});
break;
}
});
</script>
</head>
</html>
The above will give you a simple way to store variables.
Your options page needs to use the background.html to save variables to
<html>
<head>
<title>Extention options</title>
<script type="text/javascript">
window.myOptions = {
init:function(){
chrome.extension.sendRequest({action:"getItem",item:"optionOne"}, function(response) {
console.log("!responce.value"+response.value);
document.getElementById("optionOne").checked = (response.value=="off") ? false : true;
});
chrome.extension.sendRequest({action:"getItem",item:"optionTwo"}, function(response) {
console.log("!responce.value"+response.value);
document.getElementById("optionTwo").checked = (response.value=="off") ? false : true;
});
document.getElementById("optionOne").addEventListener("click",function(){
myOptions.change("optionOne");
},false)
document.getElementById("optionTwo").addEventListener("click",function(){
myOptions.change("optionTwo");
},false)
document.getElementById("resetButton").addEventListener("click",function(){
myOptions.reset();
},false)
}
,change:function(key){
var value = document.getElementById(key).checked ? "on" : "off";
chrome.extension.sendRequest({action:"setItem",item:key,value:value}, function(response) {
console.log("!responce.message"+response.message);
var m = (value == "off")? "disabled" : "enabled"
document.getElementById("settings").innerHTML = key + " has been "+ m;
});
}
,reset:function(){
chrome.extension.sendRequest({action:"clear"}, function(response) {
location.reload();
});
}
}
window.addEventListener("load", window.myOptions.init, false)
</script>
</head>
<body>
<form>
<h1>Options</h1>
<p>
Intro text
</p>
<p>
<span class="option">
<input type="checkbox" name="optionOne" id="optionOne" value="on" />
</span>
<label for="optionOne" class="wiki">Enable option one</label>
</p>
<p>
<span class="option">
<input type="checkbox" name="optionTwo" id="optionTwo" value="on" />
</span>
<label for="optionTwo" class="wiki">Enable option two</label>
</p>
<p style="height:1.3em;color:red" class="alert">
<span id="settings"></span>
</p>
<p>
<input type="button" id="resetButton" value="Reset default options"/>
</p>
</form>
</body>
</html>
Thursday, 12 August 2010
Math.random()
Note to self... for a three number 100 - 999
var min = 100
var max = 1000
Math.floor(Math.random()*(max-min)+min)
Monday, 4 January 2010
funny font size in safari on the iPhone
body {
-webkit-text-size-adjust:none;
}
Wednesday, 23 December 2009
hasLayout problems after all these years
Having terrible trouble with all version of IE trying to get some peekaboo text to stay put. In this scenario a div was not paying ball at all, after setting hasLayout on pretty much every element in the entire page I realised that the system was outputting HTML without a DTD, dogh, I feel like i've just called tech support to complain about not being able to print, only to find out that the cleaner unplugged the printer.
Note to self, always check the most obvious thing first!
In IE7 I have a normal input type = button which as the behaviour that when you scroll the text in the button gets visually corrupted. So very slowly scrolling the button into view will wipe the text and the button will appear empty. The offending button is fine in IE6 and IE8, I was tempted to ignore this and mark it down as a bug in the browser but weakened and decided to fix it.
After tinkering with the CSS for a while I couldn't find any hack/fix for this issue, setting the writing-mode style to top to bottom, did fix it but didn't think having the button text written out vertically would go down well!
In the end....
total MADNESS !
Note to self, always check the most obvious thing first!
In IE7 I have a normal input type = button which as the behaviour that when you scroll the text in the button gets visually corrupted. So very slowly scrolling the button into view will wipe the text and the button will appear empty. The offending button is fine in IE6 and IE8, I was tempted to ignore this and mark it down as a bug in the browser but weakened and decided to fix it.
After tinkering with the CSS for a while I couldn't find any hack/fix for this issue, setting the writing-mode style to top to bottom, did fix it but didn't think having the button text written out vertically would go down well!
In the end....
window.attachEvent ('onscroll', function(){
// layout fix for IE7 disappearing text, element has layout so resorting to this madness!
document.getElementById('buttonMoreSections').style.backgroundColor=(document.documentElement.scrollTop % 2)? '#fff':'white';
})
total MADNESS !
Subscribe to:
Posts (Atom)