Click to See Complete Forum and Search --> : Newby question???


p2bc
08-06-2003, 09:09 AM
I been tinkering with javascripts, and html for about 2 weeks now. (Oh yes, a real fresh one here, greener than green.)

Anyways, I have a question about calling a script.


<script language="javascript">
function openwindow()
{
window.open('index.html','newWin','width=400,height=300,left=20,top=20,toolbar=No,location=No,scroll bars=Yes

,status=No,resizable=Yes,fullscreen=No'); NewWindow.focus(); void(0);
}
</script>


This is the code I have in my header. I want to call it from the body of my page, but I do not want to use a form button application.

Example:

<form>
<input type=button value="Open Window" onclick="openwindow()">
</form>


Which would creat a big grey button on my page. I would rather it look as though action command

Example:

<a href="index.html">Open Window</a>


How can I do that. Also how can I do it so that I can call the javascript command for several site. As it is right now it is set for index.html, but lets say I call it for index1, index2, index3, and so on, on the same page without rewriting the script.

If anyone could help me out I would appreciate it.

Thanks.

pyro
08-06-2003, 11:34 AM
Try something like this:

<script type="text/javascript">
function openwindow(url) {
NewWindow = window.open(url,'newWin','width=400,height=300,left=20,top=20,scrollbars=1,resizable=1'); //this all needs to be on one line
NewWindow.focus();
void(0);
}
</script>
</head>
<body>
<p><a href="index.html" onclick="openwindow(this.href); return false;">Open a new window</a></p>That will also have the advantage of keeping the link working for those with javascript disabled.

p2bc
08-07-2003, 03:06 AM
Ok, here is the code that I am using in its simplest form, until it works there is not much point to complicate it.


<html>
<head>
<script language="javascript" type="text/javascript">
function openwindow(url)
{
NewWindow = window.open(url)
}
</script>
</head>
<body>
<a href="rasmus_bogoe.html" onclick="openwindow(this.href); return false;">Bog&oslash;, Rasmus</a>
</body>
</html>


*goes and comes back*

Here is the thing, I copied and pasted from the file I am working on to this post, which doesn't work properly, hence why I am writing this new post. Nothing more than that, I simply added <head>, <body>, and <html> tags, besides that pure copy/ past. Now looking at the code again after placing it in the post I say to myself, this should work. So I pasted the very code you see up on top in a new file, and guess what it works. What do I mean by that, in my original work, the html page being called did open, which tells me the action command works. But it did not open it in a pop up window, it open the called html page in the browser of the first page. Now the new page, the one I pasted the code you see on the top. When I click the link, it opens the page as well, but in a pop up window.

So my question now is, why does the code from the first file works as it is suppose to in the second file, but does not work in the first file properly.

p2bc
08-07-2003, 03:45 AM
:D :D :D I forgot to put a terminator "</script>" to another script that came before it. So it was not detecting it, the script with the pop up window.

I found it only after A LOT of swearing.

Thanks anyways.

pyro
08-07-2003, 07:10 AM
Lol... you bet... ;)