473,394 Members | 1,866 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,394 software developers and data experts.

new window with picture

Hello all!

I would like to open a new window with a picture after clicking on a
shrinked picture which is located on the main page. I want this new window
to be
exactly sized as original dimensions of this image.
Where is the error on the following code??? :

<SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">
function rozmiar(rysuneczek,id)
{
obrazek=new Image()
obrazek.scr=rysuneczek

if (id==1)
{
//rozmiar=obrazek.width
}
else
{
rozmiar=obrazek.height
}

}

function funkcja(rysunek)
{
oknoObrazka=window.open(rysunek,'oknoObr','toolbar =yes,location=yes,scrollba
rs=yes,width=' + rozmiar(rysunek,1) + ',height=' + rozmiar(rysunek,2))
oknoObrazka.focus()
}

</SCRIPT>
......
<a href="javascript:funkcja('WojtStol_files/meble/100_0135.gif');"><img
src="WojtStol_files/meble/100_0136.gif" width=150 height=100 border=1></a>
......

Thanks for help
Marcin from Poland
Jul 23 '05 #1
3 1421
Kamyk <ma**************@poczta.onet.pl> wrote in message
news:d4**********@news.onet.pl...
Hello all!

I would like to open a new window with a picture after clicking on a
shrinked picture which is located on the main page. I want this new window
to be
exactly sized as original dimensions of this image.
Where is the error on the following code??? :

<SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">
function rozmiar(rysuneczek,id)
{
obrazek=new Image()
obrazek.scr=rysuneczek

if (id==1)
{
file://rozmiar=obrazek.width
}
else
{
rozmiar=obrazek.height
}

}

function funkcja(rysunek)
{
oknoObrazka=window.open(rysunek,'oknoObr','toolbar =yes,location=yes,scrollba rs=yes,width=' + rozmiar(rysunek,1) + ',height=' + rozmiar(rysunek,2))
oknoObrazka.focus()
}

</SCRIPT>
.....
<a href="javascript:funkcja('WojtStol_files/meble/100_0135.gif');"><img
src="WojtStol_files/meble/100_0136.gif" width=150 height=100 border=1></a>
obrazek.scr=rysuneczek Should be: obrazek.src=rysuneczek

Your function rozmiar() must be coded to return a value, or the statements:
width=' + rozmiar(rysunek,1) and height=' + rozmiar(rysunek,2) will evaluate
to undefined.

Having said that, if you want the dimensions to be calculated rather than
specified manually, it may be better to write the function so that it need
be called only once, by having it return a string of the form:
"width=w,height=h"
rozmiar=obrazek.height

This creates a global variable with the same name as the function, which has
the effect of destroying the function.

You still need further code to display the image in the new window.
--
Stephen Chalmers


Jul 23 '05 #2


--
--D. McKirahan
DM********@comcast.net
"Kamyk" <ma**************@poczta.onet.pl> wrote in message
news:d4**********@news.onet.pl...
Hello all!

I would like to open a new window with a picture after clicking on a
shrinked picture which is located on the main page. I want this new window
to be
exactly sized as original dimensions of this image.
Where is the error on the following code??? :

<SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">
function rozmiar(rysuneczek,id)
{
obrazek=new Image()
obrazek.scr=rysuneczek

if (id==1)
{
//rozmiar=obrazek.width
}
else
{
rozmiar=obrazek.height
}

}

function funkcja(rysunek)
{
oknoObrazka=window.open(rysunek,'oknoObr','toolbar =yes,location=yes,scrollba rs=yes,width=' + rozmiar(rysunek,1) + ',height=' + rozmiar(rysunek,2))
oknoObrazka.focus()
}

</SCRIPT>
.....
<a href="javascript:funkcja('WojtStol_files/meble/100_0135.gif');"><img
src="WojtStol_files/meble/100_0136.gif" width=150 height=100 border=1></a>
.....

Thanks for help
Marcin from Poland

One problem is that you misspelled ".src" as ".scr".

Try the following "as-is"; watch for word-wrap.

<html>
<head>
<title>Marcin.htm</title>
<script type="text/javascript">
var x = 0;
var y = 0;
function rozmiar(rysuneczek) {
var obrazek = new Image();
obrazek.src = rysuneczek;
x = obrazek.width;
y = obrazek.height;
}
function funkcja(rysunek) {
rozmiar(rysunek);
var z = "scrollbars=no,width=" + (x+20) + ",height=" + (y+20);
oknoObrazka=window.open(rysunek,'oknoObr',z);
}
</script>
</head>
<body>
<a href="javascript:funkcja('WojtStol_files/meble/100_0135.gif');"<img src="WojtStol_files/meble/100_0136.gif" border="1" width="150" height="100"></a>
<hr>
<a
href="javascript:funkcja('http://www.google.com/intl/en/images/logo.gif');"<img src="http://groups-beta.google.com/images/google_sm.gif"

border="1" width="143" height="59"></a>
</body>
</html>

The width and height are padded because of the default margins.

Why would you want "scrollbars=yes" if it's supposed to fit the new window?

Also, why include "toolbar=yes,location=yes," as they clutter the new
window?
Jul 23 '05 #3
DU
McKirahan wrote:
--
--D. McKirahan
DM********@comcast.net
"Kamyk" <ma**************@poczta.onet.pl> wrote in message
news:d4**********@news.onet.pl...
Hello all!

I would like to open a new window with a picture after clicking on a
shrinked picture which is located on the main page. I want this new window
to be
exactly sized as original dimensions of this image.
Where is the error on the following code??? :

<SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT">
function rozmiar(rysuneczek,id)
{
obrazek=new Image()
obrazek.scr=rysuneczek

if (id==1)
{
//rozmiar=obrazek.width
}
else
{
rozmiar=obrazek.height
}

}

function funkcja(rysunek)
{

oknoObrazka=window.open(rysunek,'oknoObr','toolbar =yes,location=yes,scrollba
rs=yes,width=' + rozmiar(rysunek,1) + ',height=' + rozmiar(rysunek,2))
oknoObrazka.focus()
}

</SCRIPT>
.....
<a href="javascript:funkcja('WojtStol_files/meble/100_0135.gif');"><img
src="WojtStol_files/meble/100_0136.gif" width=150 height=100 border=1></a>
.....

Thanks for help
Marcin from Poland

One problem is that you misspelled ".src" as ".scr".

Try the following "as-is"; watch for word-wrap.

<html>
<head>
<title>Marcin.htm</title>
<script type="text/javascript">
var x = 0;
var y = 0;
function rozmiar(rysuneczek) {
var obrazek = new Image();
obrazek.src = rysuneczek;
x = obrazek.width;
y = obrazek.height;
}
function funkcja(rysunek) {
rozmiar(rysunek);
var z = "scrollbars=no,width=" + (x+20) + ",height=" + (y+20);


The default margin on root element is 15 for top and bottom and 10 for
left and right in MSIE 6. So here, you have miscalculated the height
with +20. I noticed you removed scrollbars for no given reason when, if
your calculations are wrong or correct - whatever -, you should always
provide normal fallback mechanisms to take over. You removed implicitly
capability to resize the window for the user and you removed explicitly,
intentionally capability to scroll the window if needed, if content
overflows requested window dimensions.
oknoObrazka=window.open(rysunek,'oknoObr',z);
}
</script>
</head>
<body>
<a href="javascript:funkcja('WojtStol_files/meble/100_0135.gif');"
<img src="WojtStol_files/meble/100_0136.gif" border="1" width="150"
height="100"></a>
<hr>
<a
href="javascript:funkcja('http://www.google.com/intl/en/images/logo.gif');"
<img src="http://groups-beta.google.com/images/google_sm.gif"


border="1" width="143" height="59"></a>


If javascript support is disabled, then the user won't be able to view
the image at all. If the user uses Ctrl+click or middle-click on the
link, he won't be able to view the image at all.

Top Ten Web-Design Mistakes of 2002;
6. JavaScript in Links
http://www.useit.com/alertbox/20021223.html

comp.lang.javascript FAQ:
"javascript:" links
http://jibbering.com/faq/#FAQ4_24
</body>
</html>

The width and height are padded because of the default margins.

Why would you want "scrollbars=yes" if it's supposed to fit the new window?
Just in case the designer miscalculated the margin on the root element.

Also, why include "toolbar=yes,location=yes," as they clutter the new
window?


If the user wants to bookmark the page, removing toolbar and location
bar won't help. If the user wants to use the toolbar - whatever the
reason - say to print the image -, your code not only removes the
toolbar but also prevents the user from getting it back on.

DU
--
The site said to use Internet Explorer 5 or better... so I switched to
Firefox 1.0.3 :)
Jul 23 '05 #4

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

Similar topics

2
by: Dariusz | last post by:
I have a problem with a call a Javascript "window.open()" function which is executed as part of a PHP file when a user clicks on an thumbnail image. The PHP is executed which passes some variables...
4
by: Phillip Parr | last post by:
Hello, I have a nice system where someone clicks on a picture to show the full version. This pops up in a window.open box. It works great, the only problem is that if the user clicks a second...
1
by: Danny | last post by:
hi, lately i've been working on a website and i have used a bit of javascript although i'm not an expert in this mather. On the page there are 3 thumbnails and when you click on a thumbnail a...
7
by: Merlin | last post by:
Hi there, I have a serious problem with opening a new window with the help of JavaScript. The problem only occures with Firefox. Once you click on the item which fires up the open function, the...
2
by: MM | last post by:
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,height=260,resizable=0,border=0")' value=Shhow...
33
by: randau | last post by:
Linking to a Targeted Browser Window I'd like to open reference links to other web sites in a separate browser window from the browser window hosting my own web site pages. The Link Target...
0
by: kloplop321 | last post by:
I found this code(vb only) and it does about the same thing(in vb, not vb .NET 2005) Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute...
9
by: tshad | last post by:
This was posted before but the message got messed up (all NLs were stripped out for some reason). I have 2 labels that hold the name of different images on my .aspx page. <asp:Label ID="Logo"...
2
by: jodleren | last post by:
Hi! I am making an option, which opens a small window with a picture in it and data about it. I just want a JS script, which will get the picture size, and then set the window accordingly? ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.