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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Size of the _blank window 7

Status
Not open for further replies.

mrkyn

MIS
Jan 30, 2002
78
US
I have the following HTML code:

<a href= “a.html” target= “_blank”>

How can I control the size of the new opened window.
Thank you.
 
Not with HTML. You will have to resort to javascript for that:
Code:
<a href= "a.html" target="_blank" onclick="window.open('a.html','mywindow','width=100,height=100';">Link</a>
This will open in a new 100x100 window for people with JS enabled and a normal new window for the rest.
 
Thanks for the help. Do you think I can also control the position of the opened window?
 
Yes. Add the location parameters in with width and height

Code:
onclick="window.open('a.html','mywindow','width=100,height=100,top=20,left=20';">Link</a>

There is a different set that works for NS, but those above work for IE.

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
Code:
[COLOR=grey]instead of:[/color] onclick="window.open([COLOR=red]'a.html'[/color],
[COLOR=grey]use:[/color] onclick="window.open([COLOR=red]this.href[/color],
It means that if you change the link's href, you only have to change it in one location. It's also easier to reuse the code.

<marc> i wonder what will happen if i press this...[ul][li]please tell us if our suggestion has helped[/li][li]need some help? faq581-3339[/li][/ul]
 
I am using this code to open a new IE window but the link opens a blank About.htm and then another window. How doI get rid of the blank window.

Any ideas please help
Thank you.
 
Use any of these:

href="#"
href="javascript:;"
href="javascript:void();"

... and remove target="blank".
 
The problem with that, vongrunt, is that people (and search engines) with Javascript switched off won't get the link to work.

Here's how to do it:
Code:
<a href= "a.html" target="_blank" onclick="window.open(this.href,'mywindow','width=100,height=100');[b]return false;[/b]">Link</a>

Now, if you have Javascript switched on, the [tt]window.open[/tt] command opens the new window, and the [tt]return false;[/tt] causes the <a> tag to fail - so it doesn't open a second new window.

If Javascript is switched off, the [tt]onclick[/tt] event is ignored, so the link is opened in a new window because of the [tt]target[/tt] attribute, albeit without the nice window sizing.

This approach obeys the golden rule for Javascript: Use JS to enhance the user experience, don't make it a compulsory component of it.

-- Chris Hunt
 
In that particular case I must admit this is nice example of "graceful degradation".

Otherwise... Javascript off is too much degradation to me.
 
Tried this code and the prev suggestions from Von and it gives me an invalid argument error when I click on the code.
Also I use Vbscript and asp, and I am writing this out as a string.

Here's what I have in the ViewCode section of the page

<A Href='./dir1/page.asp?sess_id=12' target='_blank' title='List of all students enrolled for this class' onclick="javascript:window.open('this.href','List of Trainees','width=100,height=100');return false; "> View </A>

Any ideas why I am getting a error. The new page does open, but it doesn't show the right dimensions. Looks like the href is getting executed but not the window.open script.

Any ideas pls let me know.

Thanks
 
Thank you.
Tried that but still getting the same error, any other ideas?
 
try List_of_Trainees instead of List of Trainees for the popup window name. It might not like the spaces.

Tony
________________________________________________________________________________
 
This becomes interesting... works in moz, fails in IE.

Ack... second parameter (window name) must not contain spaces in IE. Change it to 'ListOfTrainees' or something.
 
<A Href='./dir1/page.asp?sess_id=12' target='_blank' title='List of all students enrolled for this class' onclick="javascript:window.open('this.href','List of Trainees','width=100,height=100');return false; "> View </A>

javascript: isn't needed in onclick...

News and views of some obscure guy
 
I am using VBScript on all my pages, so I guess Javascritp is needed.

Anyways, my page is opening without any scrollbars, it cannot be resized and the maximize button is disabled.
Here's the code :-
onclick="&"""javascript:window.open(this.href,'ListofTrainees',resizeable=1,scrollbars=1)

Any help appreciated.
 
Once you start specifying window attributes in the window.open(...) command, all non-named attributes default to 0 or off or none or whatever. Therefore, you will need to specify which ones you want when calling window.open(...). Here is a link to available attributes:


'hope that helps.

--Dave
 
LookingForInfo, instead of scrollbars=1 try
scrollbars=yes );">
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top