You are not logged in.

#1 07 Feb 2008 12:10 am

azzlack
Senior Member
From: Bergen, Norway
Registered: Jan 2008
Posts: 26
Website

Javascript popup

I have tried to make a mashup of different javascript snippets i've found, to generate a popup that loads every 60 seconds when a user enters a page.

However, the function that is supposed to check if the popup windows exists and the close it before it opens it again does not seem to work. You can take a look at the script here: test.eyecatch.no.

Code:

<script type="text/javascript">

var winpops = null;
var popurls=new Array()
popurls[0]="http://goscie.myminicity.com"
popurls[1]="http://goscie.myminicity.com/ind"

function openpopup(popurl){
winpops=window.open(popurl,"","width=,height=")
winpops.blur()
window.focus()
}

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

popfrequency="1 minutes"

function resetcookie(){
var expireDate = new Date()
expireDate.setMinutes(expireDate.getMinutes()-10)
document.cookie = "jkpopunder=;path=/;expires=" + expireDate.toGMTString()
}

function loadornot(){
if (get_cookie('jkpopunder')==''){
if (winpops && winpops.open) winpops.close;
openpopup(popurls[Math.floor(Math.random()*(popurls.length))])
var expireDate = new Date()
expireDate.setMinutes(expireDate.getMinutes()+parseInt(popfrequency))
document.cookie = "jkpopunder="+parseInt(popfrequency)+";path=/;expires=" + expireDate.toGMTString()
}
}

if (get_cookie('jkpopunder')!=parseInt(popfrequency))
resetcookie()
loadornot()

</script>

Does anyone have a clue as to why it doesnt work? I do not get any JS errors in FireBug...

Last edited by azzlack (07 Feb 2008 12:10 am)


Web Developer and Designer.
Currently studying for Bachelor of Computer Science degree ...

Offline

 

#2 07 Feb 2008 1:36 pm

SpecialNight
New Member
Registered: Dec 2006
Posts: 1

Re: Javascript popup

did you tried to set a name property?
for example this code:

Code:

<script>
    function openpopup(popurl){
        winpops=window.open(popurl,"Window_Name","width=,height=")
    }

    openpopup("http://www.yahoo.com");

</script>

first will open a new window (which have the name "Window_Name"), if you run this function again, so
if the window exists,it will reload it...

Offline

 

#3 10 Mar 2008 3:32 am

azzlack
Senior Member
From: Bergen, Norway
Registered: Jan 2008
Posts: 26
Website

Re: Javascript popup

Thanks! It works perfectly now.


Web Developer and Designer.
Currently studying for Bachelor of Computer Science degree ...

Offline

 



© 2003 - 2019 NullFX
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License