开发者

Set Javascript height in document instead of external script

开发者 https://www.devze.com 2023-02-22 22:27 出处:网络
I have an external Javascript file that enables a popup within a webpage. I would like to use the script to have multiple popups with different heights, but the height is set in the external file. So

I have an external Javascript file that enables a popup within a webpage. I would like to use the script to have multiple popups with different heights, but the height is set in the external file. So here's the relevant Javascript:

myHeight = ((y/2)-(400/2)); //400 is popup height
popup.style.top = (myHeight + bdy_ref.scrollTop) + 'px';
}

function popup(windowname) {
toggle('blanket');
toggle(windowname);
blanket_size(windowname);
}

And here's the link that calls in the webpage:

<a href="javascript:void(0);" onclick="popup(开发者_开发技巧'popup');">Click here</a>

So my question is, if I can set the windowname in the webpage, can I also set myHeight in the webpage, so I can have multiple popups with multiple heights while keeping just the one script?

Thank you.


JavaScript has functions to resize the window, but they can be disabled in the browser's configuration (at least in Firefox).


you need to pass your popup window size to popup function :

function popup(windowname, width, height) {
   //set the size here
   toggle('blanket');
   toggle(windowname);
   blanket_size(windowname);
}

in this way you can set window size for each window.

Note Your javascript code should create different instances of window for each function call, unless you can not do this.

Edited due to your comment You can not do it without editing your external js file (a bit)

but the easier way can be like this :

//not changed 
   function popup(windowname) {
       toggle('blanket');
       toggle(windowname);
       blanket_size(windowname);
    }

    function SetSize(width, height)
    {
       //set window size
    }

and call it like this :

<a href="javascript:void(0);" onclick="SetSize(400,500);popup('popup');">Click here</a>

in this way you need to add just one function called SetSize to your js without editing its other codes. a function witch just sets width and height variable.

0

精彩评论

暂无评论...
验证码 换一张
取 消