How can I get the width of an image for a bookmarklet ?

So I want to create a bookmarklet that when you click redirects you to the reddit submission page & puts the width of the image you currently have opened up in the title.

I can do that with this, basically all I need to replace is what follows after title='+

javascript:location.href='http://www.reddit.com/submit?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)

Now I also got an alert working that shows me the width of an image with alert(image.naturalWidth)

But I can't for fucks sake figure out how it could work in the bookmarklet, google doesn't help and I tried everything from encodeURIComponent(image.offsetWidth), (naturalWidth) to (location.href.naturalWidth)

Could anyone help me there ? I feel like this just needs a quick fix.

Edit: done thanks to BattleshipsGame

Posted Dec 2, 2012, 4:52 PM UTC · edited

213
Loading comments…