Forum Moderators: open
function moreInfo(val1,val2,val3,val4){
var windowWidth="width=";
var windowHeight="height=";
var comma=",";
var quote="'";
var windowAttr=",resizable=no,scrollbars=no,location=no,directories=no,status=no,menubar=no";
var attributes=quote.concat(windowWidth).concat(val3).concat(comma).concat(windowHeight).concat(val4).concat(comma).concat(windowAttr).concat(quote);
window.open(val1,val2,attributes);
}
And on the link
href=javascript:onClick=moreInfo('more_info.html?id=Display_name','MoreInfo','100','100')
The window opens in Safari but it Firefox and IE the address and status bars remain, I've looked for a number of alternatives and they all seem to do the same.
You don't need to specify "yes" or "no" for window attributes. Include them if you want them,
windowAttr='resizable,scrollbars,location,directories,status,menubar';
Or leave them out if you don't.
windowAttr='resizable,scrollbars';
You should never turn off resizable, and should leave scrollbars in too, although you may get a "perfect window" in your environment, you never know what your end users' settings may do. There's nothing more annoying than vital content inaccessible down below the window frame. Scrollbars will only appear if they are needed, that is, if the content width/height exceeds the window.
The parameters of window.open are window name/id, url, parameters. The name attribute is to assign a unique id to the window to insure it always opens a new window. Using a "same name" will load new content in the same window, which can give the impression your site is broken.
- User clicks link, new window opens.
- Without closing new window, user clicks back into main window and clicks another link.
- Content loads in pop up already open, which is now behind the main window, giving the impression "nothing happens."
Last, return false from your function. This allows you to use a live link in the event JS is disabled. Return false allows Javascript to take over and tells the browser not to navigate to the url in HREF.
All this in mind, here's a simplification of your
function. I've used descriptive variables rather than generic ones, makes it easier to understand.
<a href="more-info.html" onClick="return moreInfo(more-info.html',400,500);">Mo' Info</a>
function moreInfo(url,w,h){
// Use date/time to assign a unique id
var day = new Date();
var id = day.getTime();
// Taking advice about resizable/scrollbars
// To ignore this, change to
// var windowAttr = 'width='+w+',height='+h;
var windowAttr = 'width='+w+',height='+h+',scrollbars,resizable';
window.open(id,url,windowAttr);
return false;
}