Forum Moderators: open

Message Too Old, No Replies

Javascript error - used to work

         

chuckee

11:10 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



Hi, the following popup code of mine produces the following error :
Line: 55
Char: 1
Error: 'win2' is null or not an object

It used to work, so I was wondering what has happened.
Thanks!

<script>

//specify page to pop-under
var popunder="/surveys.php"

//Pop-under only once per browser session? (0=no, 1=yes)
//Specifying 0 will cause popunder to load every time page is loaded
var once_per_session=1

///No editing beyond here required/////

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset!= -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function loadornot(){
if (get_cookie('popunder')==''){
loadpopunder()
document.cookie="popunder=yes"
}
}

function loadpopunder(){
win2=window.open
win2=window.open(popunder,'captaincook','width=500,height=300')
win2.blur()
window.focus()
}

if (once_per_session==0)
loadpopunder()
else
loadornot()

</script>

JAB Creations

3:37 am on Jun 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I could be wrong or I could just be getting used to my own mistakes!

I think you need to put a semicolon at the end of that line! Do that, check the JS error (if you get any) and work from there. Best of luck!


win2=window.open;

kaled

10:37 am on Jun 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The functional code is

function loadpopunder(){
window.open(popunder,'captaincook','width=500,height=300');
window.focus()
}

Calling blur() is probably pointless since you are calling window.focus() afterwards but you could use

window.open(popunder,'captaincook','width=500,height=300').blur();

However, in these days of popup-blockers, you probably need something like this.

function loadpopunder(){
var popw = window.open(popunder,'captaincook','width=500,height=300');
if (popw) popw.blur(); // probably pointless
window.focus()
}

However, I think this can be further simplified, in most cases to

function loadpopunder(){
var popw = open(popunder,'captaincook','width=500,height=300');
if (popw) popw.blur(); // probably pointless
focus()
}

Kaled.