I'm trying to reload the browser with a url link clicked in fancybox by the user so the parent window will go to the url after fancybox has closed, but only if the link is clicked and not when fancybox is closed normally. I open an asp file in fancybox that uses google maps api to show an interactive map. I'm testing when a marker is clicked, the infowindow opens with a link, which is a new location. I've gotten fancybox to close and the parent window reloads, but for some reason I cannot get the parent location to change to the new url! I feel that it should be working because everything else works and it's got me totally baffled.
The code in my asp file, which uses google maps api, looks like this:
var contentstring = document.createElement("div");
contentstring.innerHTML = '<div id=\"content\">'+
'<div id=\"siteNotice\">'+'</div>'+
'<div id=\"bodyContent\">'+'<b>'+'<a href=\'http://www.lookathawaii.com/proddetail.asp?prod=96816-DIAMOND-HEAD-STATE-MONUMENT\' onclick=\"parent.$.fancybox.close(); parent.location.assign(\'http://www.lookathawaii.com/proddetail.asp?prod=96816-DIAMOND-HEAD-STATE-MONUMENT\'); parent.location.reload(true); return true\">'+'Diamond Head State Monument, Park and Trail'+'</a>'+'</b>'+'</div>'+
'</div>';
contentstring.className = "map-popup";
contentstring.style.height = "60px";
var infowindow = new google.maps.InfoWindow({content: contentstring});
google.maps.event.addListener(marker9, 'click', function() {
infowindow.open(map,marker9);
});
Another strange thing I noticed is that although I created the afterClose construct in the fancybox $.ready function, it doesn't get called when I force fancybox to close with parent.$.fancybox.close() but it gets called if I close fancybox normally. I should add that the code above is called inside the head section of my asp file rather than the body. I've been hacking this thing all night and I still don't see what's wrong. I would greatly appreciate any help to get this working.
To summarize, the calls within fancybox to close and reload the new url are:
parent.$.fancybox.close();
parent.location.assign(new-url);
parent.location.reload(true);
But for some reason, fancybox closes and reloads the parent with the existing/old url.
EDIT - I just noticed that in Google Chrome, the callback function afterClose() is getting called, but in IE11 it's not getting called. For both browsers, the fancybox closes and reloads, but neither of them will assign the new url. This is the main reason I want to use fancybox instead just a new window popup.
I also forgot to mention, the url I'm testing the google maps api is on http://www.lookathawaii.com/proddetail.asp?prod=96815-THE-FAT-GREEK click on the "Map" tab then click on the map image (then drag the map toward north-west so you can see diamond head, which is south-east, then click the Marker in the middle of diamond head to see the infowindow popup with the link which should take users to my diamond head page). One more thing, the fancybox gets called from the url I'm testing like this:
<a href="maps/96815-test1.asp?prod=96815-THE-FAT-GREEK&lat=21.284329&lng=-157.836873" class="fancybox fancybox.iframe">
I solved it with a very small change to my original code. I used the original 3 calls to:
based on what I read many people here say. However, what I learned is that calling 'reload(true)' is not necessary and actually messes things up for some reason. When I tested this order:
it worked perfectly and reloaded the parent window with the new url! So I made that simple change in my contentstring and it worked perfectly again! Now I've created a map with a handful of test locations where a user can go anywhere on my website from the map (tested in IE11 and Chrome).
I'm not sure why the first 3 calls that have been suggested didn't work, maybe it's a browser issue, but the two calls necessary are 'assign(new-url)' and 'close()' in that exact order. The browser will refresh automatically after the fancybox is closed without any call to 'reload()'.
You may need to create a temporary element in your parent page and target that element's ID from the child (iframed) page so try
In your parent page :
Now, on your child page :
Since you are creating the variable
contentstring
for your marker, you may prefer to place the script inside a function and call it withinonclick
passing thehref
as parameter, but you can get the big picture from the code above.See DEMO at picssel.com
NOTES: