why I hate javascript (vol I)

  • Thread starter Testin da Cable
  • Start date
T

Testin da Cable

Guest
well, for a girl I know I'm fiddling with a bit of js. she wants a window to open of a certain size when a link is clicked, but for some odd reason she doesn't want to use html (or as little as she can)

here is the code:
Code:
<html>
<head>
<script language="javascript">
<!-- have to hide the script
function openWin(img) {
winId = window.open('');
    winId.document.write('<body><center>');
winId.document.write('[img]' + img + '[/img]');
winId.document.write('<script language="javascript">');
winId.document.write('var Element = document.getElementById("Image");');
winId.document.write(' var w = document.getElementById("Image").width;');
winId.document.write(' var h = document.getElementById("Image").height;');
winId.document.write('window.resizeTo((w * 1.1), (h * 1.1));');
winId.document.write('</script>');
  winId.document.write('</center></body>');
winId.document.close();
}
-->
</script>
</head>
<body>
[url="javascript:openWin('test.jpg')"][img]t_test.jpg[/img][/url]


</body>
</html>

I'm utterly failing for obvious reasons. But it got so late at night that my only thougt was to post it here. help me. please...help :)
 
T

Testin da Cable

Guest
yeah, but the trick is, I need the window to resize to the size of the image opened -without knowing the image's size beforehand :/

thanks for the link btw :)
 
J

Jonty

Guest
Can we use a dash of PHP, please? This would make things sooo much easier, as it's hideously complicated to get a image's width dynamically. Either that or will all the images use a fixed ratio to govern the thumbnail and large image sizes?

Kind Regards
 
T

Testin da Cable

Guest
well, her server doesn't support it sadly enough :/ goodness, I see I've managed to leave out a line in the code!! stupid me will edit :/
anyway, I was thinking of trying someting like document.getElementById("Image").width and the same for height. if there are such definitions that is, javascript and I don't mix very well :/

I attempt to do away with margin nastys (as they tend to vary a bit) by popping the image, then expanding the window by 10%
 
J

Jonty

Guest
I believe you're after .offsetWidth and .offsetHeight. I've worked for hours trying to make this work 'properly' (since the document.write method is a very bad way of doing things). However, unless you have either PHP support, or all the images utilise the same ratio or you put the height and width in the image file name (i.e. 'image1.800.600.jpg') then there's little one can do to avoid using the above method.

Sorry :(
 
T

Testin da Cable

Guest
:(


I'll figure something out in the end ;)
 
T

Testin da Cable

Guest
well, I've managed to get it working via a slight cheat and a combination of javascript and css. look here for results
 
T

Testin da Cable

Guest
yes, this one is worst luck :/ I couldn't figure out an easy way to do it dynamically, so I lazed out and didn't do it. it seems she's already put the image dimentions into her pages as it is so this is a minor change for her (I hope heh)
 
T

Testin da Cable

Guest
I'm messing with it atm

this is what I've gotten now:

Code:
<script language="javascript" type="text/javascript">
<!--
var win=null;
var w=null;
var h=null;
function NewWindow(mypage,w,h){
settings='width="+ w +", height="+ h +",scrollbars=no,location=no,directories=no
,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,settings);
alert("width= " + w + " height=" +h+" ");}
-->
</script>

and I use this line on the popper:

Code:
[url="pop.html"]test[/url]

and due to the built in alert I can see the w and h variables...but the darn thing just won't work. I can't see what I'm doing wrong :/
 
J

Jonty

Guest
window.open takes three arguments, source, window ID, and settings. You simply omitted the second, hence it didn't like it. Try this :)

Code:
<script type="text/javascript">
// <![CDATA[
function Window (Source, ID, Width, Height)
{
  var Settings = "Height="+Height+",Location=No,Menubar=No,Resizeable=No,Scrollbars=No,Status=No,Toolbar=No,Width="+Width+"";
  window.open(Source, ID, Settings);
}
// ]]>
</script>

...

[url="pop.html"]Image One[/url]
Kind Regards
 
T

Testin da Cable

Guest
well bugger me it works now :D

I hope you're at that BarryBeer Jonty :)
 
J

Jonty

Guest
Is there another one any time soon? To be honest, though, I don't know all that many people here at BarrysWorld.

Glad everything's working :D

:bazbeer:

Kind Regards
 
T

Testin da Cable

Guest
aye, there's one april 5th in Edinburg so I hear :)
 
J

Jonty

Guest
Really? Cool :) I doubt I'll be going all the way up there, though. Not after the last time. *Jonty blushes at the thought of haggis* ;) teeheehee

Kind Regards
 
T

Testin da Cable

Guest
well I can understand that. for some strange reason there is a certain person on these forums who is determind to force me to eat haggis...and I'm not up to that challange I kid you not :eek7:
 
J

Jonty

Guest
hehe, I won't ask who, for fear he'll turn on me. But, if minced sheep's heart, liver, and lungs with onion, oatmeal, suet, seasonings, lemon juice, and stock, all wrapped in a sheep's stomach is his thing, then ... well ... I can't finish that sentence :p hehe :D

Kind Regards
 

Users who are viewing this thread

Similar threads

W
Replies
6
Views
966
wyrd_fish
W
W
Replies
3
Views
623
wyrd_fish
W
T
Replies
6
Views
504
Mr. 47
M
W
Replies
4
Views
859
evilmonkeh
E
W
Replies
3
Views
522
Wilier
W
Top Bottom