Click to See Complete Forum and Search --> : popup with cookies... need to fix


onyxxxx
May 13th, 2008, 01:15 PM
Hi, I have a simple html website and I want that music would play in it. I decided to use a JS popup window. But I have one problem with my script. It has cookies with session:


<script type="text/javascript">
var popurls=new Array()

popurls[0]="music/dance.html"
popurls[1]="music/dj.html"
popurls[2]="music/hiphop.html"

function openpopup(popurl){
var winpops=window.open(popurl,"","width=370,height=10")
}
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('jkpopup')==''){
openpopup(popurls[Math.floor(Math.random()*(popurls.length))])
document.cookie="jkpopup=yes"
}
}
loadornot()
</script>


So, when the popup is loading it's ok. When I am going through pages which have the same popup link, the popup is not refreshing, which is also good. But when popup has a different link (for example "hiphop.html") it is not refreshing.

Is it possible to make a different link to work in this popup?

PeejAvery
May 13th, 2008, 03:43 PM
I'm a little confused by your explanation. Are you saying that you have a grouping of pages which will make the popup go to one specific page, and other groupings of pages that make the popup redirect to a different specific page?

Note: Popup blockers will block the opening of a popup unless it is user interacted, such as an onclick event. This will greatly affect the implementation of your code.

Personally, I would stick with using the AJAX method, as discussed in your other thread (http://www.codeguru.com/forum/showthread.php?t=452669).

onyxxxx
May 14th, 2008, 11:29 AM
Yes. Exactly, there is a several group of pages. The popup window should open by a link, but only if it's another link in a popup. If the popup link (music/dance.html) is the same going through several same group pages, the popup should not refresh.

Is it possible?

PeejAvery
May 14th, 2008, 12:03 PM
Why can't you just create your own custom function which controls the url of the popup? Then you can call that function within the links.

<script type="text/javascript">
function popUpURL(url) {
var popup = your popup handler
if (popup.location != url) {popup.location = url;}
}
</script>

<a href="" onclick="popUpURL('http://www.example.com/page.html')">Link</a>