/    Sign up×
Community /Pin to ProfileBookmark

Hi all! I am new to the forum, and JavaScript

Hi ALL!
I read a crap book about Javascript. It gave me lots of examples, so I know enough to cause trouble, but it didn’t really explain anything, so I don’t understand 90% of what I am doing – so forgive the stupid questions.

I want a function to open a window with “something.htm” in it and set the picture that something.htm is displaying. Okat I managed this, but there is a problem. I seem to be able to use JavaScript to set the new windows picture and size of the picture, but I can’t find out how to set the size of the window. I can hard code it, but that is not the point. I want to pass the window size to the function as parameters so that it is in proportion to the picture. Either that or I want to do this in a completely different way. The aim here is to scale the something.htm window according to the size of the picture I want something.htm to display.

By the way, when I try to set various properties in the new window, frontpage often complains, yet in the browser, the code works fine?? Is this normal??

Any thoughts lads?

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@TageMay 29.2004 — Maybe something like this?[code=php]<html>
<head>
<script type="text/javascript">
<!--
function openImgWin(theImg,theTitle,theHeight,theWidth){
theWindow=window.open("about:blank","imgWin","height="+theHeight+",width="+theWidth);
theWindow.document.write("<html><head><title>"+theTitle+"</title></head><body leftmargin='0' topmargin='0' style='margin:0px'><img src='"+theImg+"' height='"+theHeight+"' width='"+theWidth+"' alt='"+theTitle+"'></body></html>")}
//-->
</script>
</head>
<body>
<a href="javascript:openImgWin('plus.gif','Some Image','320','320')">Open Image Window</a>
</body>
</html>[/code]
But for some reason, it won't work with Opera... O.o? I don't know why! Maybe someone else has a better script.

Tage
Copy linkTweet thisAlerts:
@SuzanneBauthorMay 30.2004 — Hi!

GREAT! Thanks, thats good.My problem was syntax.

I was repeatedly getting this bit wrong..

("about :blank","imgWin","height="+theHeight+",width="+theWidth);

I need a better book!

I modified it a bit to define a window width and picture width, one being the other plus a bit.

Although I might add that Frontpage complains, even about this code. Only when the page is running for real does it work.

What I did for the image was to have a page I made earlier! Called bill with buttons and stuff, with a blank picture in it called bob say. Then I have the code in the function in the parent window

bill.bob.src=theImg;

bill.bob.height=theHeight;

bill.bob.width=theWidth;

( bearing in mind that bill's height and width are set to slightly greater than this, for a nice border and some buttons!)

this allows me use a "pre-constructed" window to display the picture.

Frontpage *****es about this too, but in the real world, it SEEMS to work okay. Calling on your greater experience, do you think it is okay??

What does everyone else use? I can't believe the entire world uses Frontpage.


function zoom(imgName,imgWidth,imgHeight)

{

winHeight=imgHeight+100;

winWidth=imgWidth+100;

zoomWindow = Window.open('zoom.htm','imgWin',

'height='+winHeight+',width='+winWidth);

zoomWindow.zoomImg.src=imgName;

zoomWindow.zoomImg.width=imgWidth;

zoomWindow.zoomImg.height=imgHeight;

zoomWindow.focus();

}
Copy linkTweet thisAlerts:
@SuzanneBauthorMay 30.2004 — Hmm....there is something wrong with my approach...sometimes it does not get the picture...also once the window is open, it ignores subsequent size changes. I need to close the window then re-open it.

My GREAT book gives and example of this as

if (imgWindow && !imgWindow.closed){
imgWindow.close();
}


The only minor problem is I need to call this FIRST and the code does not work. the first part (if) imgWindow is supposed to check if the window exists, which does not work at all - as you would expect. It gives the error "undefined", which kinda makes me think the author is a total idiot.

My lovely book does not say how to declare the window without creating it.
Copy linkTweet thisAlerts:
@TageMay 30.2004 — X.x I'm a bit sleepy, but to resize the window after it has loaded, you can use window.resizeTo(height,width) in the pop-up window itself OR theWindow.resizeTo(height,width) from the parent (theWindow being specifically from the code I gave you, it is the var holding the window.open() function). I use Notepad... O.O Lol. That book does sound a bit odd... O.o

Tage
Copy linkTweet thisAlerts:
@TageMay 30.2004 — Maybe, the code tries to change the img src,height,and width before the code has loaded the img tag? Hm...

Edit: I don't know what approach is better than the other. I only look for what's compatible with the latest (stable) versions of internet explorer, netscape, mozilla, and opera.

Another Edit: Looking for more compatibilities than me may be good, since I really don't work on any commercial sites or anything like that. Lol :rolleyes:

Tage
Copy linkTweet thisAlerts:
@SuzanneBauthorMay 30.2004 — I am trying to resize in the child, but how do I read the size I need from the parent?
Copy linkTweet thisAlerts:
@SuzanneBauthorMay 30.2004 — I am getting fed up now! I can happily write to the child, but I can't read from the parent. Maybe this isn't possible? How do you pass data from on to the other then??
Copy linkTweet thisAlerts:
@WebskaterMay 30.2004 — window.parent

references the parent window

if you had variables in script on the parent window like

<script>

var winheight=300

var winwidth=300

</script>

you reference them on the child window as:

window.parent.winheight

etc.

What is FrontPage doing? I use it all the time because, like most html editors it does the very useful job of colour coding your code so you can easily see which bits are client-side script, server-side script and html. Notepad may be the purist's choice but I've used both and give me FrontPage anytime.

It is best just to use FrontPage as an html editor. Do not be tempted to add form components or use its script generating abilities. This should all be coded by hand and FrontPage's webbots avoided.
×

Success!

Help @SuzanneB spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...