Click to See Complete Forum and Search --> : new window


jazzyjade
06-06-2003, 09:31 AM
I use this script all the time and it works just fine. But now, instead of opening a new window, the page opens in the same window. The only thing that's different is that I'm working in a frameset but I'm not sure how that would make a difference.


This code is in an external js file:

//This script opens, sizes, and centers the new window
var theWin = null;
function winOpen(url) {
var l = Math.round((screen.availWidth - 788)/2);
var t = Math.round((screen.availHeight - 543)/2);
var sWid = (document.layers) ? 'outerWidth' : 'width';
var sHgt = (document.layers) ? 'outerHeight' : 'height';
theWin = open(url,'theWin',sWid+'=788,'+sHgt+'=543,left='+l+',top='+t+',status=no,resizable=no,');
setTimeout('theWin.focus()',100);
}

And is called on a page within this function (the function works properly and makes it into the if statement fine, the problem seems to be within winOpen().

function feedback(){
if (setLayer[0]==1){
winOpen('cs1_css.htm');
}

Khalid Ali
06-06-2003, 09:42 AM
The code you have is should be working fine..it should open a new window with the URL provided,
one thing though..

change this line

theWin = open(url,'theWin',sWid+'=788,'+sHgt+'=543,left='+l

to

theWin = window.open(url,'theWin',sWid+'=788,'+sHgt+'=543,left='+l

Now back to your problem..I have a feeling that you are calling this function from a link.And in that link there are couple of things tha can effect..

you might have target="_self"

if true the get rid of it.
in the onclick event of the link

onclick = "feedback(); return false;"

make sure you put return false...

Hope this solves it..

jazzyjade
06-06-2003, 10:01 AM
I added the window reference to the open command and I added return false; but it didn't seem to work.

Also, I'm not calling the function within a link tag. I call the function from within another function which is called when a user clicks a div on the page. Should I try calling it from a link tag or wouldn't that make a difference?

Khalid Ali
06-06-2003, 10:03 AM
that is not necessary..post a link to the actual pages..so that some one can take a look

jazzyjade
06-06-2003, 10:17 AM
I wish I could provide a link but I work on an intranet. The code is very long and complicated but I'll try to provide a small amount of the relevant code here. (Keep in mind that everything else works just fine.)

Page with reference to code:
<body>

<div id="submit" class="chcformbut" onMouseDown="down(this)" onMouseUp="out(this)" onClick="checkanswer()">Submit</div>

</body>

External Code:
function checkanswer(){
submitClicked = submitClicked+1;
parent.hidden.css = submitClicked;
feedback();
return false;
}

function feedback(){
winOpen('cs1_css.htm');
}

//This script opens, sizes, and centers the new window for css screens
var theWin = null;
function winOpen(url) {
var l = Math.round((screen.availWidth - 788)/2);
var t = Math.round((screen.availHeight - 543)/2);
var sWid = (document.layers) ? 'outerWidth' : 'width';
var sHgt = (document.layers) ? 'outerHeight' : 'height';
theWin = window.open(url,'theWin',sWid+'=788,'+sHgt+'=543,left='+l+',top='+t+',status=no,resizable=no,');
setTimeout('theWin.focus()',100);
}

Khalid Ali
06-06-2003, 10:29 AM
I still can't reproduce what you are talking about..I used all of your code in a frame and clicked on left frames where it says "Submit" and it opened a new window....

jazzyjade
06-09-2003, 09:26 AM
Ah ha! I got it to work. Why do I even bother trying to accomplish anything on a Friday? A clear head on Monday morning and it all made sense :)

Since I had already used the script once with the course the variable theWin had already been used and was the name of the current window, so when I tried opening a new window called theWin, of course it wouldn't open in a new window. So all I had to do was change the variable name.

Only one slight problem now. On the page that uses the new window script, after the new window opens and I return to the old window, I get an error message that says my (newly named) window variable, theNewWin, is null or not an object. I guess I could leave it since everything works O.K. but it's a little annoying and I'd like to know why it's happening.

//This script opens, sizes, and centers the new window for css screens
var theNewWin = null;
function winOpen(url) {
var l = Math.round((screen.availWidth - 788)/2);
var t = Math.round((screen.availHeight - 543)/2);
var sWid = (document.layers) ? 'outerWidth' : 'width';
var sHgt = (document.layers) ? 'outerHeight' : 'height';
theWin = window.open(url,'theNewWin',sWid+'=788,'+sHgt+'=543,left='+l+',top='+t+',status=no,resizable=no,');
setTimeout('theNewWin.focus()',100);
}