Connecting Tech Pros Worldwide Forums | Help | Site Map

opening a new window (with options) by clicking on an image

Newbie
 
Join Date: Jan 2007
Posts: 4
#1: Jan 23 '07
Hello all thescripts users...

I am currently working on my first bit of HTML (modifying a template), and I am learning lots of cool new stuff. I have come across a problem. I would like to be able to open a new browser upon clicking on an image. By itself, this is pretty easy, however the complicating factors is that I would like my new browser to be of specific dimensions and without scrollbars.

I have seen numerous examples which show me how to do this if I click on a form button, such as:

[HTML]<FORM>
<INPUT type="button" value="New Window!" onClick="window.open('http://www.pageresource.com/jscript/jex5.htm','mywindow','width=400,height=200')">
</FORM>[/HTML]

however I don't want to use a form button! I want to use an arbitrary image.

Grateful for any tips people might have...

Regards,

John



iam_clint's Avatar
Forum Leader
 
Join Date: Jul 2006
Location: Oklahoma
Posts: 1,076
#2: Jan 23 '07

re: opening a new window (with options) by clicking on an image


This is really a javascript question -- but I am not a mod of html so someone else will move your post over after they read this..

but for example this would work.
[HTML]
<img src="whatever.jpg" onclick="window.open('http://www.pageresource.com/jscript/jex5.htm','mywindow','width=400,height=200');">
[/HTML]


Full window.open Documentation
http://www.w3schools.com/htmldom/met_win_open.asp
Newbie
 
Join Date: Jan 2007
Posts: 4
#3: Jan 24 '07

re: opening a new window (with options) by clicking on an image


Thank you for that answer, very helpful.

I noticed that when I incorporate this code, when I hover the mouse over the image, the pointer doesn't turn into a hand indicating a link. Is there any way to have the pointer turn into a hand as if it was a regular link?

Regards,

John
iam_clint's Avatar
Forum Leader
 
Join Date: Jul 2006
Location: Oklahoma
Posts: 1,076
#4: Jan 24 '07

re: opening a new window (with options) by clicking on an image


add this attribute to the image
style="cursor: pointer;"

such as
<img src="blah.gif" style="cursor: pointer;">
Newbie
 
Join Date: Jan 2007
Posts: 4
#5: Jan 24 '07

re: opening a new window (with options) by clicking on an image


fantastic help Clint. I really appreciate it. Go TheScripts.com!!!
Reply


Similar JavaScript / Ajax / DHTML bytes