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

Very basic popup windows

Status
Not open for further replies.

iwgalloway

Programmer
Joined
Jan 24, 2006
Messages
3
Location
CA
Hi - I have a text link in a html page. I'd like it to open another page in a popup window when I click it...

I know I can do this with javascript, and that there's a line of code which contains all the options [like toolbars on/off, size of window etc]

What is it and how do i attach it to some text in my very simple html page??

Thanks
 
The javascript function is:
Code:
window.open("[i]URL[/i]", "[i]window_name[/i]", "[i]attribute1[/i]=value, [i]attribute2[/i]=value");
Replace 'URL' with the URL of the page to open in the window.

Replace 'window_name' with whatever name you would like the new window to have.

Replace 'arrtibute1' with an attribute listed below. Attributes not listed default 0. All attributes that you would like; should be listed within the third set of double quotes, separated by a comma.

Replace 'value' with a value associated to the attribute

Attribute Values
width number
height number
directories yes, no, 1, 0
location yes, no, 1, 0
menubar yes, no, 1, 0
resizable yes, no, 1, 0
scrollbars yes, no, 1, 0
status yes, no, 1, 0
toolbar yes, no, 1, 0

to use the javascript in a link change your a tag to something like this:
Code:
<a href='#' onclick='window.open("[i]URL[/i]", "[i]window_name[/i]", "[i]attribute1[/i]=value, [i]attribute2[/i]=value");return false;'>click here</a>
The 'onclick' attribute of the a tag tells the browser to execute the code when the link is clicked. The return false after the window.open() call tells the browser to ignore the value in the 'href' attribute.
 
Itshim said:
Attributes not listed default 0

Not always. They only default to 0 if any option is listed. If no options are listed the default to a standard set of options (such as having a URL bar, status bar, etc)... so you can do this:

Code:
var winHandle = window.open('url', 'winName', '');

to get a new window without having to specify things like 'toolbar=1,status=1', etc.

Note also that for security reasons, some browsers will not let you turn off the status bar, or create windows smaller than a certain size (around 100x100 pixels, IIRC).

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top