Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New window opening with fixed size. 1

Status
Not open for further replies.

Eldaria

Programmer
Sep 20, 2001
123
NL
Hi guys,

How can i make a link, so that when the user click on it, it will open a new window, but the new window should have a fixed sixe, and no toolbars, addressbar, etc...

I want to use it on a site where a user can click on an item to get more information, and this should then open ain a new window.

Regards.
Brian


Eldaria

That was my 25cent** of opinion.

** Inclusive Intrest, tax on interest, Genral tax, Enviromental tax, Tax, and tax on intrest, tax on fees, tax on tax, and other Various taxes and fees.
 
Use javascript window.open function:

<script language=&quot;JavaScript&quot;>
function openNewWindow(){
window.open(&quot;newwindow.asp&quot;, &quot;toolbars=0,scrollbars=0,menubar=0,status=0,resizable=1,width=500,heght=300,left=0,top=0&quot;);
}

}
</script>

<a href=&quot;javascript:eek:penNewWindow();&quot;>Open New window</a>

Just keep in mind that the user can hit Ctrl-N keys, which will open the same pop-up window but with all attributes(toolbars, scrollbars, etc.)
 
Sorry for my Ignorance, but I know nothing about Javascript.

How can I make the page it shoould load an argument, or do I need to have one script for each link?

I want to include it in an ASP page where I have all scripts in one asp file so I can reuse it on all pages.

I have one asp file subs.asp

It looks something like this.

<%
Sub subone(argument)
the code goes here.
end sub

sub subtwo(argument)
more code here
end sub
%>

This one I then 'include' in the asp pages where I need code.
and the code for the new window will be used hundreds of times.

Regards.
Brian



Eldaria

That was my 25cent** of opinion.

** Inclusive Intrest, tax on interest, Genral tax, Enviromental tax, Tax, and tax on intrest, tax on fees, tax on tax, and other Various taxes and fees.
 
You can use a js include as well:
type the script in Notepad, save it as a file with js extention (myscripts.js) in some directory in your web application. Then you can refernece this file in <HEAD> of your page. In this sample the file is residing in &quot;scripts&quot; directory on the root.

<head>
<script language=&quot;JavaScript&quot; src=&quot;/scripts/myscripts.js&quot;></script>
</head>

Now all functions in the js file are available and can be called from the page.
 
Ok cool, so I have one include for VB script and one for Java script.

And how can i call the script from before with an argument?

So that I can have it in the &quot;<A href=&quot;
What I can see the link is currently in the code itself, between the <Script> and </Script>

Regards,
Brian


Eldaria

That was my 25cent** of opinion.

** Inclusive Intrest, tax on interest, Genral tax, Enviromental tax, Tax, and tax on intrest, tax on fees, tax on tax, and other Various taxes and fees.
 
Can you post a block of current code that is creating those links?
 
Ok this is the link builder.
It is the first response.write that types out the link.

rs.movefirst
do until rs.eof
lineid = lineid + 1
occid = rs.fields(&quot;Description&quot;).value
desc = rs.fields(&quot;Description&quot;).value
%>
<td align=&quot;center&quot;>
<%
response.write(&quot;<a href='occ.asp?occ=&quot; & occid & &quot;' target='_Blank'><img src='gfx/Occasion/Occ&quot; & occid & &quot;a_100.jpg' border='1' alt='Druk voor meer informatie.'></img><br>&quot;)
response.write(desc & &quot;</a>&quot;)
%>
</td>
<%
rs.movenext
if lineid = 4 then
%>
</tr>
<%
if rs.eof
else
%>
<tr>
<%
end if
loop


Eldaria

That was my 25cent** of opinion.

** Inclusive Intrest, tax on interest, Genral tax, Enviromental tax, Tax, and tax on intrest, tax on fees, tax on tax, and other Various taxes and fees.
 
Uups there where several errors in that code,

this is a working version...

<%
rs.movefirst
do until rs.eof
lineid = lineid + 1
occid = rs.fields(&quot;occid&quot;).value
desc = rs.fields(&quot;Description&quot;).value
%>
<td align=&quot;center&quot;>
<%
response.write(&quot;<a href='occ.asp?occ=&quot; & occid & &quot;' target='_Blank'><img src='gfx/Occasion/Occ&quot; & occid & &quot;a_100.jpg' border='1' alt='Druk voor meer informatie.'></img><br>&quot;)
response.write(desc & &quot;</a>&quot;)
%>
</td>
<%
rs.movenext
if lineid = 4 then
%>
</tr>
<%
if rs.eof then
else
%>
<tr>
<%
end if
end if
loop
end if


Eldaria

That was my 25cent** of opinion.

** Inclusive Intrest, tax on interest, Genral tax, Enviromental tax, Tax, and tax on intrest, tax on fees, tax on tax, and other Various taxes and fees.
 
First, modify the javascript so the function will except an argument to be passed to a new window via the querystring:
function openNewWindow(occId){
window.open(&quot;occ.asp?occ=&quot; + occId, &quot;toolbars=0,scrollbars=0,menubar=0,status=0,resizable=1,width=500,heght=300,left=0,top=0&quot;);
}

Server side script will now look like this:

<%
...
response.write(&quot;<a href='javascript:eek:penNewWindow(&quot; & accId & &quot;);'><img src='gfx/Occasion/Occ&quot; & occid & &quot;a_100.jpg' border='1' alt='Druk voor meerinformatie.'></img><br>&quot;)
response.write(desc & &quot;</a>&quot;)
...
%>
 
I get an error when clicking on the link.

Error: Invalid Argument
Line: 2


Also is it possible to make it more generic?
so that when user click on the link it will send the entire link to be opened in a new window?
Then I can re-use the code in other situations than this specific script.



Eldaria

That was my 25cent** of opinion.

** Inclusive Intrest, tax on interest, Genral tax, Enviromental tax, Tax, and tax on intrest, tax on fees, tax on tax, and other Various taxes and fees.
 
Let's fix the existing script and make sure it works: when you mouse over the link, what do you see in the status bar(bottom left of the window)? Should be something like javascript:eek:penNewWindow(5);
 
Correct, that is what I see, the number follows the link ID(OccID)
 
Sorry. Please modify the JavaS_subs.js so it'll look like this:

function openNewWindow(occId){
window.open(&quot;occ.asp?occ=&quot; + occId, &quot;&quot;, &quot;toolbars=0,scrollbars=0,menubar=0,status=0,resizable=1,width=500,heght=300,left=0,top=0&quot;);
}

You might probably want to play with widht, height, left and right parameters to make the new window look good.
 
Thanks. What was your idea about makeing the script more generic?
 
So that I can use it to open any other page, and not only the one from this script.

Kind of sending the entire path to the scrip and not only the pageID..

 
OK, I see. Instead of hard coded &quot;newwindow.asp&quot; in the function. You can have the javascrupt functions except two arguments: occId and url:

function openNewWindow(path, occId){
var path = path + &quot;?occId=&quot; + occId;
window.open(path, &quot;&quot;, &quot;toolbars=0,scrollbars=0,menubar=0,status=0,resizable=1,width=500,heght=300,left=0,top=0&quot;);
}

and modified server side script(note I changed single quotes to two double quotes):
<%
...
Response.Write(&quot;<a href=&quot;&quot;javascript:eek:penNewWindow('occ.asp',&quot; & accId & &quot;);&quot;&quot;><img src=&quot;&quot;gfx/Occasion/Occ&quot; & occid & &quot;a_100.jpg&quot;&quot; border=&quot;&quot;1&quot;&quot; alt=&quot;&quot;Druk voor meerinformatie.&quot;&quot;></img><br>&quot;)
...
%>

If you had page URL stored in the database, then it could be real dynamic.
 
Well this pag is in the future going to have a content management, where the store can make their own changes....

But that is well into the future. :)

But thanks for the last piece of Code, I will try it out another day, because now I have to go to work, and I'm unable to access the server for editing from there, (Firewall/Proxy)

But thanks a lot...
Brian

 
Hi LV

Looking at the code you posted:

<script language=&quot;JavaScript&quot;>
function openNewWindow(occId){
window.open(&quot;occ.asp?occ=&quot; + occId, &quot;&quot;, &quot;toolbars=0,scrollbars=0,menubar=0,status=0,resizable=1,width=500,height=300&quot;);
}
</script>
<a href=&quot;javascript:eek:penNewWindow();&quot;>Open New window</a>

How can you get the New Window to center (or centre in the UK!) when the visitor clicks on the hyperlink?

Many thanks
KB

(By the way, I changed heght to height as in your original post not that it made much difference anyway) Thanks again

When everything else is said and done, there will be nothing else to say or do
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top