473,385 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

need help opening a window

MM
I am using the following code to display an image in a seperate
window.

<form>
<input type=button
onClick='window.open("image1.jpg","","width=260,he ight=260,resizable=0,border=0")'
value=Shhow Picture'>
</form>

I want the window to be the exact size of the image so I set the width
and height of the window the same as the width & height of the image.

The code works, however there is a white border on the top and left
side of the image. If I add 20 to the width and height of the window
then there is a white border around the whole image.

Is there anyway to have the window the exact size of the image,
without this white border? I know there is probably a simple solution,
but I'm a beginner at JavaScript.

Any help is much appreciated.
Jul 23 '05 #1
2 1374

"MM" <ca***********@yahoo.ca> wrote in message
news:jv********************************@4ax.com...
I am using the following code to display an image in a seperate
window.


do you really need a new window? I think "thumbnail>big image in new
window" is a pita. also, pop up blockers will block you.

sorry to not answer your ?.
Jul 23 '05 #2
MM wrote:
I am using the following code to display an image in a seperate
window.

<form>
<input type=button
onClick='window.open("image1.jpg","","width=260,he ight=260,resizable=0,border=0")'
value=Shhow Picture'>
</form>

I want the window to be the exact size of the image so I set the width
and height of the window the same as the width & height of the image.


You can't reliably do this for all browsers. Some automatically put a
margin of 20px or so on all <body> tags by default. Some also add it
when showing just an image, but others not. Safari adds it when
showing a page, but not when showing an image.

Even if you manage to set the margin to 0, some browsers will leave a
border on the other side of the image (IE on Mac). So the simplest
solution is to put all your images into HTML documents and load those
(setting margin to 0).

Another solution is to leave a good margin of say 50px around the
image and set your background to some compatible colour (black seems to
be the most common choice). For an image of width 300 and height 200,
create a window of an extra 100px and add 50px padding to the image:

<script type="text/javascript">
function showPic(t,u,w,h) {
w -= -100;
h -= -100
newWin = window.open('','','height=' + h + ',width=' + w);

var sHTML = [
'<html><head><title>' + t + '</title></head><body',
' style=\'margin: 0; background-color: black;',
' color: black;\'><img src=\'' + u + '\'',
' alt=\'\' border=\'0\' style=\'padding: 50 0 0 50\'>',
'</body></html>'
];

newWin.document.write(sHTML.join(''));
newWin.document.close();
}
</script>

</head><body>

<form action="">
<input type="button" value="Show Picture" onClick="
showPic('A Picture','image1.jpg','300','200');
">
</form>

Incidentally, pop-up blockers will normally allow pop-ups in response
to user actions, but some allow even those to be blocked. Some also
allow exceptions for certain sites.

But in general, pop-ups are bad.

--
Rob
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Johnny Knoxville | last post by:
I've added a favicon to my site (http://lazyape.filetap.com/) which works fine if you add the site to favourites the normal way, but I have some JavaScript code on a couple of pages with a link,...
3
by: Steve | last post by:
Hi, I have a nice little script that works well displaying images on my website. It's a script where if you clik a thumbnail image a pop up window opens that contains a larger version of the same...
2
by: Dena Leiter | last post by:
I want to send people to a new page using a redirect but I want a new window to open. Is this possible? I've tried this: <meta http-equiv="refresh"...
2
by: tmb | last post by:
- Want to open a 2nd browser window when someone clinks a link with the link content inside it. - Want to control window size - Want all tool bars so only blue bar at top shows - Can I put my...
1
by: Jarrod Hyder | last post by:
Ok, I wrote my own weblog and I'm working on the web interface for adding/editing my posts. I decided to add a little preview button...when the button is clicked it is suppose to open a pop-up...
14
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
2
by: Keshav Gadia | last post by:
Hi, I am an ASP.net newbie. I am writing a user control that is made up of datagrid with one of the columns opening a new window to display some details on click of the set image. I have...
5
by: Roger Withnell | last post by:
This is a framed webpage with the navigation bar in "NavBar" and the main window in "Main". When opening a new page in "Main" from "NavBar" with: function OpenFrameWindow(src) { var...
7
by: fox | last post by:
Hi, Lacking javascript knowledge, I just realized why my project has a bug. I am using ASP to loop through a set of records while it creates URLs with a querystring that has a single value pair....
1
by: sandy21380 | last post by:
Hello, Is there a way of opening an Access form without opening the Access window? Right now when I open the form, the Access window is a lot bigger than the form so I have to resize the Access...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.