Joined: 24 Nov 2003 Posts: 2465 Location: Paris - France
Posted: 07.09.2007 15:03 Post subject: javascript: onload resize popup
bok svima!
mozete li mi , molim vas reci, kako napraviti resize nekog popup-a u duzinu, ovisno o sadrzaju?
sadrzaj je dinamican znaci ne znam koliko je popup visok, znam samo sirinu, no ove scriptove sto sam dosad vidjela tretiraju width ali height mi se slozi kako mu se hoce: kao da postoji neki default height (iako ga nigdje nemam).
postoji li mogucnost regulacije visine tog popupa? ako je sadrzaj dug scroll nije problem no kad imam deset linija sadrzaja ostane mi praznog okolo. no nikad ne znam koliki mi je sadrzaj.
unaprijed puno hvala
ps. naravno ideja nije moja nego od obozavanog klijenta
Poz, sljedeci kod postavi u neki.js file koji ces ucitavati na stranici gdje se nalaze linkovi za popup.
Code:
window.onload = attachEvents;
function attachEvents()
{
var popupList = getElementsByClassName("popUp");
for(var i = 0; i < popupList.length; i++)
{
if(popupList[i].href != "undefined")
{
popupList[i].onclick = doIt;
}
}
}
function doIt()
{
var popup = makePopup(this.href, 640, 480, 'resize');
popup.onload = function()
{
getHeight(popup);
}
return popup.closed;
}
function getElementsByClassName (className) {
var all = document.all ? document.all :
document.getElementsByTagName('*');
var elements = new Array();
for (var e = 0; e < all.length; e++)
{
if (all[e].className == className)
elements[elements.length] = all[e];
}
return elements;
}
function getHeight(popup)
{
var y;
var test1 = popup.document.body.scrollHeight;
var test2 = popup.document.body.offsetHeight
if (test1 > test2) // all but Explorer Mac
{
y = popup.document.body.scrollHeight;
}
else // Explorer Mac;
//would also work in Explorer 6 Strict, Mozilla and Safari
{
y = popup.document.body.offsetHeight;
}
setHeight(y, popup);
}
function setHeight(y, popup)
{
y += 20;
if (popup.self.innerHeight) // all except Explorer
{
popup.self.innerHeight = y;
}
else if (popup.document.documentElement && popup.document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
popup.document.documentElement.clientHeight = y;
}
else if (popup.document.body) // other Explorers
{
popup.document.body.clientHeight = y;
}
}
Predpostavio sam da koristiš anchor elemenat (ako nisi trebat ce malo ispraviti kod)
uglavnom da bi ti ovo funkcionisalo trebas uraditi sljedeca 2 koraka:
1 - (već sam rekao al evo ponoov) - Sav JS code kopirati u neki js file koji ce biti uključen u stranicu gdje su linkovi prema popup -ima
2. Staviti class-u popUp na link koji zelis da se otvara u popup-u
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum