sethwb
06-09-2009, 04:13 AM
Let's say I have script with multiple variables lines functions in it...
How do I enter it into the "location" bar when creating a bookmarklet?
Here's some random code I grabbed to use as an example:
function alertSize() {
var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
window.alert( 'Width = ' + myWidth );
window.alert( 'Height = ' + myHeight );
}
Before you say anything yeah I know this code is stupid for a bookmarklet but it was the first thing I saw so... just for learning purposes :D
I find that when I removed all the spaces it just doesn't do anything, but no errors are returned either... what am I doing wrong?
How do I enter it into the "location" bar when creating a bookmarklet?
Here's some random code I grabbed to use as an example:
function alertSize() {
var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
window.alert( 'Width = ' + myWidth );
window.alert( 'Height = ' + myHeight );
}
Before you say anything yeah I know this code is stupid for a bookmarklet but it was the first thing I saw so... just for learning purposes :D
I find that when I removed all the spaces it just doesn't do anything, but no errors are returned either... what am I doing wrong?