parent.location.assign(url)无法使用fancybox iframe [英] parent.location.assign(url) not working from fancybox iframe

查看:172
本文介绍了parent.location.assign(url)无法使用fancybox iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重新加载浏览器,用户在fancybox中点击了一个url链接,因此父窗口将在fancybox关闭后转到url,但前提是单击链接而不是fancybox正常关闭时。我在fancybox中打开一个asp文件,它使用google maps api来显示交互式地图。我正在测试点击标记时,infowindow会打开一个链接,这是一个新位置。我已经关闭了fancybox并且父窗口重新加载,但由于某种原因我无法将父位置更改为新的URL!我觉得它应该工作,因为其他一切都有效,这让我感到困惑。

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.

我的asp文件中使用google maps api的代码如下所示:

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

我注意到的另一个奇怪的事情是,虽然我在fancybox $ .ready函数中创建了afterClose构造,当我强制fancybox与父级关闭时,它不会被调用。$ .fancybox.close()但是如果我正常关闭fancybox它会被调用。我应该补充一点,上面的代码是在我的asp文件的head部分而不是body中调用的。我整夜都在黑客攻击这件事,但我仍然没有看到什么是错的。我非常感谢能帮助您实现这一目标。

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.

总而言之,fancybox中关闭并重新加载新网址的调用是:

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

但由于某种原因,fancybox关闭并使用现有/旧网址重新加载父级。

But for some reason, fancybox closes and reloads the parent with the existing/old url.

编辑 - 我刚刚注意到在谷歌Chrome中,调用了回调函数afterClose(),但在IE11中它没有被调用。对于这两种浏览器,fancybox关闭并重新加载,但它们都不会分配新的URL。这是我想使用fancybox而不只是一个新窗口弹出窗口的主要原因。

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.

我也忘了提及,我正在测试google maps api的url是打开的 http://www.lookathawaii.com/proddetail.asp?prod = 96815-THE-FAT-GREEK 点击地图标签然后点击地图图像(然后将地图向西北方向拖动,这样你就可以看到东南方的钻石头,然后点击在钻石头中间的标记,看到infowindow弹出窗口的链接,应该将用户带到我的钻石头页)。还有一件事,fancybox从我正在测试的url中调用:

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">


推荐答案

我通过对原始版本进行了非常小的更改解决了这个问题码。我使用原来的3个电话:

I solved it with a very small change to my original code. I used the original 3 calls to:

    parent.$.fancybox.close();
    parent.location.assign(new-url);
    parent.location.reload(true);

基于我在这里看到很多人所说的内容。然而,我学到的是,调用'reload(true)'并不是必需的,并且实际上由于某种原因弄乱了。当我测试此订单时:

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:

    parent.location.assign(new-url);
    parent.$.fancybox.close();

它完美运行并使用新网址重新加载父窗口!所以我在我的内容字符串中做了那么简单的改变,它再次完美地工作了!现在我创建了一个包含少量测试位置的地图,用户可以从地图上访问我网站上的任何位置(在IE11和Chrome中测试)。

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).

我'我不确定为什么前3个调用被认为不起作用,也许这是一个浏览器问题,但必要的两个调用是按照确切的顺序'assign(new-url)'和'close()'。关闭fancybox后,浏览器将自动刷新,而不会调用'reload()'。

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()'.

这篇关于parent.location.assign(url)无法使用fancybox iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆