18 April, 2010

Make Images open in a popup window

Blogger Logo Grey
All you bloggers on blogspot ,you must have noticed that when you upload any image to blogger,blogger gives you three sizes (small ,medium ,large)and the original sized image is accessible to uses when they click on the image but the image opens in same window thus navigates your readers away from your blog.


One Nice way to avoid this is to use target="_blank" within your images anchor tag so that your images open in new window.But why not add a little frill and make the image open in a popup window.

Here,s an Example HTML code for any image


What you have to do is ADD :

target="_blank" onclick="window.open(this.href, 'popupwindow', 'width=420, height=350, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no'); return false;

after the closing double quotes enclosing the url of the original image, but before the > tag.So that result will be like this-



Let me Explain all the elements one by one.

width=520, height=520 Defines the size of the popup window

resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no are optional attributes, you can change their values to yes or no according to your needs

For demo click on the grey blogger logo (above) accompanying this post.

the target="_blank"  makes the link open in a new window

you can add the attributes top= and left= to define the position of the pop-up window

Here's an example:

    target="_blank" onclick="window.open(this.href, 'popupwindow', 'width=420, height=350, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, top=20, left=20,'); return false;"

This would make the window open with a displacement of 20 pixels from the top and left of the screen.
Values can be adjusted according to the requirement and will.

Like this article -you can view more of my posts on Images 

Previous post- Use Jquery to style your external Links
                        Image hovering by changing opacity

2 comments:

  1. really nice post!
    I was searching sor this!
    very useful.

    Thanks!

    ReplyDelete
  2. Thanks Man !!
    Your Post Help Me Alot . Very Very Very Nice Post .
    Keep Your Good Work On .

    ReplyDelete


Spam/advertising comments will NEVER BE TOLERATED and will be deleted immediately!

I advise you to also "subscribe to the comment feed" and get email updates when I respond to your question.
Thanks for reading,
Admin