开发者

Can I call a Javascript bookmarklet over just an image in browser window. e.g.:blah.com/blah.jpg?

开发者 https://www.devze.com 2023-04-11 21:24 出处:网络
If I\'m at a url... say http://i.imgur.com/JcxmE.jpg where it is just the image file, h开发者_如何学编程ow can I make a window/div appear over the image when the bookmarklet is called?

If I'm at a url... say http://i.imgur.com/JcxmE.jpg where it is just the image file, h开发者_如何学编程ow can I make a window/div appear over the image when the bookmarklet is called? Instapaper does this. So far my bookmarklet loads an external javascript file, which in turn creates a div and appends it to the body. This doesn't work when it is just an image. Ideas? Thank you!


Alright it looks like firefox still renders a DOM even over images. The hello world example works only if you stick it inside a bookmarklet, but not straight in the url bar.

Here's an example that should work as long as your browser renders a DOM even on pure image urls. It will insert the image inside a container element.

javascript:(function(){
  var doc = document,
      image = doc.getElementsByTagName('img')[0],
      container = doc.createElement('div');

  doc.body.removeChild(image);
  container.appendChild(image);
  doc.body.appendChild(container);
})();


Well it doesn't look like you can, at least not in Firefox. Even something as simple as javascript:alert('Hello World'); doesn't work on an image. Try that code for yourself.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号