PDA

View Full Version : cant figure out how to make a complex bookmarklet, please help!


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?

A1ien51
06-09-2009, 02:45 PM
Paste your code in the second box, hit the minify button: http://fmarcia.info/jsmin/test.html

Eric

rnd me
06-09-2009, 07:34 PM
firebug's console, with "use larger command line" checked, provides a "copy" button that converts all the spaces to "%20", and adds "javascript:" in front, preparing snippits for a bookmarklet in one click.

i use it a lot....

sethwb
06-09-2009, 07:49 PM
Hmm I don't see the option for use larger command line, can you help me find it? I'm looking in tools>firebug and also around in the console itself... don't see it.

sethwb
06-09-2009, 07:54 PM
Oh I see it now I had my console disabled (doh!) thanks much