PDA

View Full Version : Same page click


Cmoazz
11-13-2005, 05:53 PM
Hi all.... me again.

I have a question, is there a way to link a page so that when you click it, it opens up to a certain size pixel w x h?

If so, is there also a way to link something so that when you click it, and that window is already open, for it to just come up, but not open a new one of the same kind?

Thanks.

birdbrain
11-14-2005, 03:47 AM
Hi Cmoazz,

do you mean something like this...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>window open</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>

<style type="text/css">
/*<![CDATA[*/
div {
text-align:center;
margin-top:20px;
}
div a {
color:#000;
background-color:#fff;
}
/*//]]>*/
</style>

<script type="text/javascript">
//<![CDATA[

var w=500;
var h=330;
var l=(screen.width-w)/2;
var t=(screen.height-h)/2;
var features='width='+w+',height='+h+',left='+l+',top='+t+',scrollbars=1';

var mywindow;

function newWindow(url) {
if(mywindow) {
mywindow.close();
}
mywindow=window.open(url,'',features);
mywindow.focus();
}
//]]>
</script>

</head>
<body>

<div>
<a href="http://www.htmlforums.com/showpost.php?p=427373&amp;postcount=1"
onclick="newWindow(this.href);return false">look at my post</a>
</div>

</body>
</html>



Reason for edit:- typing error. :o
and as Bill Posters has pointed out I used the wrong template for this example. :o

Bill Posters
11-14-2005, 04:34 AM
<meta name="Content-Script-Type" content="text/javascript"/>
<meta name="Content-Style-Type" content="text/css"/>
Fwiw, both of these meta elements are redundant unless you're using inline CSS and inline javascript, which you aren't in your example - and ideally shouldn't be using anyway.

They are also redundant when using embedded CSS and embedded javascript (as you do in your example) if you [correctly] use the type attribute with the style and script elements (as you do in your example).

birdbrain
11-14-2005, 04:56 AM
Hi Bill,

thanks for pointing out the error in my template. :)
I have edited my post and removed my faux pas
Have also corrected my template. :D

Cmoazz
11-14-2005, 06:22 PM
OMG! Thank you so much, you made the HTML very clear and easy to understand and edit into my own options. Thank you sooo much it worked flawlessy! Much appreciated!

Cmoazz
11-14-2005, 10:30 PM
Umm, one problem, when you go to a different page, and you click the same link, it opens up a new page still.... doesnt bring up the one thats already open.

The other pages do also have the HTML code in them.... help?

Bill Posters
11-15-2005, 03:24 AM
If you add a name/title/reference for the popup window between the apostrophes below, then that window will be reused by future popup calls if it is already open.

e.g.

...
mywindow=window.open(url,'yourWinName',features);
...

Cmoazz
11-15-2005, 02:40 PM
Im not sure what you mean by that.. can you put it in the html for me.

Link image <img src="images/music.gif">
Link opens = music.html

For the title thing you giving me, call it 305kicks Music Player

Much appreciated, thanks.

birdbrain
11-15-2005, 03:18 PM
Hi Cmoazz,

what Bill means is add a name - (any name of your choosing :) ) - to the script, where highlighted....
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>window open</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>

<style type="text/css">
/*<![CDATA[*/
div {
text-align:center;
margin-top:20px;
}
div a {
color:#000;
background-color:#fff;
}
/*//]]>*/
</style>

<script type="text/javascript">
//<![CDATA[

var w=500;
var h=330;
var l=(screen.width-w)/2;
var t=(screen.height-h)/2;
var features='width='+w+',height='+h+',left='+l+',top='+t+',scrollbars=1';

var mywindow;

function newWindow(url) {
if(mywindow) {
mywindow.close();
}
mywindow=window.open(url,'popeye',features);
mywindow.focus();
}
//]]>
</script>

</head>
<body>

<div>
<a href="http://www.htmlforums.com/showpost.php?p=427373&amp;postcount=1"
onclick="newWindow(this.href);return false">look at my post</a>
</div>

</body>
</html>
...simple as that. :D

p.s. a one word name would be safer to use.

Cmoazz
11-15-2005, 09:44 PM
Thank you.