PDA

View Full Version : Javascript POPup Link - Only Link?


Golden_Eagle
10-01-2002, 05:16 PM
Can this be done? I want to create a controlled, centered popup. Without using anycode in the head tags.

This what I got and then gave up! :(
My javascripting is very bad I know!

Can anyone help me out?
I tried using this with onclick - but that didn't work either!

<A HREF="javascript:window.open('pop.htm','width=500','height=500'.'resize=yes','scroll=yes','location='no',' toolbar=no')">Click Here</a>

Help is hugely appreciated.......:thumbsup:

beetle
10-01-2002, 05:27 PM
Originally posted by Golden_Eagle
Can this be done?Yes, but....Originally posted by Golden_Eagle
Without using anycode in the head tags.Why?

functions are our friends....:D

adios
10-01-2002, 05:37 PM
You're assuming it's a choice between a <script></script> block in the <head>er, or inline (<a href="javascript:.....) JS in the body. Script blocks can go anywhere - just about - and, for something which requires more than a line of code, keeping as much out of the inline HTML as possible is neater, easier to maintain, and less likely to cause syntax (lexical) errors.

beetle
10-01-2002, 06:00 PM
Originally posted by adios
You're assuming it's a choice between a <script></script> block in the <head>er, or inline (<a href="javascript:.....) JS in the body. Script blocks can go anywhere - just about - and, for something which requires more than a line of code, keeping as much out of the inline HTML as possible is neater, easier to maintain, and less likely to cause syntax (lexical) errors. Ya, what he said. :D

BrightNail
10-01-2002, 10:51 PM
hello,

its a valid request....just put this in your javascript link code...

screenX=0,screenY=0,top=0,left=0

we use 'both' for netscape and IE....so, screenx is the same for top...etc...

screenX=300,screenY=400,top=300,left=400

to get it "exactly" center..you might have to do somethign like this..not sure..

screenX='+availscreen.width/2+',screenY'+availscreen.height/2+' etc.....

or somethign like that...

james

eak
10-01-2002, 11:09 PM
i still dont see why you would want to have all the js code inside the link instead of in a function block. if you ever change your mind about using the script tags, you can use my NewWindow script generator (http://www.eak.homeip.net/newwindowgenerator.html) to get the code to center the window.

joh6nn
10-02-2002, 12:32 AM
could you just use <a href="page.htm" target="popup">click click</a> and put the centering and sizing tag in the pop up window?

glenngv
10-02-2002, 10:09 AM
Originally posted by eak
i still dont see why you would want to have all the js code inside the link instead of in a function block. if you ever change your mind about using the script tags, you can use my NewWindow script generator (http://www.eak.homeip.net/newwindowgenerator.html) to get the code to center the window.

just a comment in your window generator
1. no checking for invalid inputs
2. you left out screenX and screenY features
3. generated code is one-liner and difficult to understand and debug (in case there are conflicting variables with other codes)

:)

Golden_Eagle
10-02-2002, 01:11 PM
<A HREF="javascript:void(window.open('page.htm', 'win', 'status'))">Open Popup</A>

The reason this has to be 'function-less' or without aid from a header tag. Is because this link is going to distributed onto lots of websites. I would prefer to just let them copy&paste the one link, rather than change all the head tags ec

This opens a toolbar-less window with a status bar.

Can the status bar be removed?

Resizing and scrolling be added?

It needs to be centered if possible.

And size via height/width as well.


Can this be controlled from this one link? Or is this impossible?

Posts at the beginning of this thread believes it is possible. Please help me.

Golden_Eagle
10-02-2002, 03:01 PM
Amazing what you can find if you look hard enough!

:D

<a href="#" onClick="MyWindow=window.open('http://www.yahoo.com','MyWindow,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes, resizable=yes,width=600,height=300'); return false;">Click Me</a>

Problem Solved! :)

Thanks EveryOne!

Ta Ta 4 Now!

beetle
10-02-2002, 03:23 PM
To make sure your link degrades and is compatible with non-javascript browsers (kinda rare, but search engine spiders will like this better too...)

<a href="http://www.yahoo. com" onClick="MyWindow=window.open(this.href ,'MyWindow,'toolbar=no,location=no,directories
=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=300'); return false;">Click Me</a>

Golden_Eagle
10-02-2002, 03:59 PM
Thanks. I think I'll use yours! :)

Erm... One more thing.

Is it possible to get the window to appear centered on the screen.

Without using head tags?

glenngv
10-03-2002, 03:49 AM
<a href="http://www.yahoo.com" target="MyWindow" onClick="
w=700;h=675;
posx = (screen.availWidth/2)-(w/2);
posy = (screen.availHeight/2)-(h/2);
win = window.open(this.href,this.target,'location=0,toolbar=0,resizable=1,scrollbars=1,width='+w+',height= '+h+',left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy);
win.focus();
return false;"
>Click Me</a>

you will only change the text in red color

(take note, there's no space in this.target)

eak
10-03-2002, 06:04 AM
Originally posted by glenngv


just a comment in your window generator
1. no checking for invalid inputs
2. you left out screenX and screenY features
3. generated code is one-liner and difficult to understand and debug (in case there are conflicting variables with other codes)

:)

1. i had that on an old generator but have not had time to impliment it yet
2. i have found that screenx/y are pointless. ns4 supports top/left. if i have time, i may add it in.
3. i dont see how there could be confilicting variables. i use internal local vars. i put it all on one line because it saves space.
the only reason you would need to understand/debug the code is if you are learning javascipt. that is the reason i made the generator in the first place.... to help the newbies.

glenngv
10-03-2002, 06:22 AM
what i meant with conflicting variables is, i.e., i pasted your code in my page and what if my code has the same variables with yours?

beetle
10-03-2002, 06:29 AM
glenn....Originally posted by eak
3. i dont see how there could be confilicting variables. i use internal local vars.What else needs to be said?