...

View Full Version : Pop up link (link that pops up a window)



toya
06-03-2004, 03:44 AM
first i got this script from javascriptkit.com

<script>

function openpopup(){
var popurl="mail.html"
winpops=window.open(popurl,"","width=430,height=365,toolbar,status,")
}

</script>

then the link will be like this

<a href="javascript:openpopup()"

but that only goes for 1 target (mail.html) then i tried to make another link that pops up a window with fixed size and atributes

<a href="javascript:window.open('shout.html',
'win1','width=450,height=300,menubar,scrollbars')"">

it does pops up a window, but the first window (where the link is) becomes a blank page

thanks in advance before

llizard
06-03-2004, 05:14 AM
Try this (no pun intended):



<a href="shout.html" onclick="window.open(this,'win1','width=450,height=300,menubar=1,scrollbars=1');return false;">shout</a>


The this after window.open refers to the URL after href="

The beauty of it is that it will still open even if javascript is disabled.


I have just recently been learning about popup windows and linking to and from them. The following may be of help to you:
http://llizard.crosswinds.net/cwc/popuplinks.html

glenngv
06-03-2004, 05:45 AM
The this keyword there refers to the current element which is the <a>

<a href="shout.html" onclick="window.open(this.href, ...

llizard
06-03-2004, 01:03 PM
The this keyword there refers to the current element which is the <a>

<a href="shout.html" onclick="window.open(this.href, ...

oh rats. I thought that's what I just said.... :)

the .href is optional (at least I think it's optional....)

toya
06-03-2004, 08:46 PM
wow thanks :thumbsup:
so without the this the window will go somewhere else, i got it thx

llizard
06-03-2004, 09:39 PM
so without the this the window will go somewhere else, i got it thx

Actually, it seems that without the onclick= and return false;, the window will go somewhere else.

You can still use:



<a href="shout.html" onclick="window.open('shout.html','win1','width=450,height=300,menubar=1,scrollbars=1');
return false;">shout</a>


but the "this" or "this.href" after onclick=window.open( makes it so you don't have to enter the URL twice in the same link.

(Hope that made sense)

glenngv
06-04-2004, 03:46 AM
oh rats. I thought that's what I just said.... :)

You said it also in your site (http://llizard.crosswinds.net/cwc/popuplinks.html). :D



the .href is optional (at least I think it's optional....)
I tested it in some of the browsers and yes, it turned out to be really optional.
It goes to show that the default property for the this keyword in <a> tag is the href property.
But, IMHO, it is better to explicitly define the intended property to avoid confusion and provide consistency of usage of the this keyword in all HTML elements.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum