Forum Moderators: open

Message Too Old, No Replies

Window attributes not working in IE

         

optik

11:45 pm on Oct 2, 2009 (gmt 0)

10+ Year Member



I'm using this code to open a new window via a link

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.

daveVk

1:56 am on Oct 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why does attributes begin/end with quote ?

optik

10:44 am on Oct 3, 2009 (gmt 0)

10+ Year Member



I thought they had to be there, I have removed them and it has made no difference.

rainborick

2:26 pm on Oct 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Try:

var windowAttr="resizable=no,scrollbars=no,location=no,directories=no,status=no,menubar=no";

It looks like the leading comma in your original code leads to two commas in a row being passed in the attributes for window.open(), but now I can't replicate it for some reason.
Worth a shot.

rocknbil

4:12 pm on Oct 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure what you're doing with the window size, but an empty value is bound to cause problems. You can use methods to get/set a width height, or hard code them. Overall, the approach can be simplified.

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;
}

optik

1:11 pm on Oct 4, 2009 (gmt 0)

10+ Year Member



Apparently Microsoft have blocked the removal of the address bar for security reasons as of IE7.

I'm going to look into using dynamic div's instead.

Thanks for your help though.