从 iframe 中打开链接

发布于 2025-01-07 19:58:17 字数 783 浏览 5 评论 0原文

我会尽量保持简短。我有一个包含各个部分的页面。其中一个部分有一个 iframe,其中包含谷歌地图。在信息窗口上,我有一个链接,单击该链接时,我希望它在页面上的花式框中打开(不在 iframe 中......我可以做到这一点)。例如,如果我有一个链接说“google”,我喜欢它打开 http://www.google.co .uk/ 在 fancybox 中覆盖整个页面。

我有 2 个不同的页面和 2 个 JavaScript,1 个用于地图(iframe),另一个用于主页。该函数位于主页脚本中。

我认为我出错的地方是a)打开页面的正确调用b)将一个类附加到javascript,即class =“fancybox”。

我的地图信息窗口中有此链接(map.js):

<a href="javascript:parent.openSomething();">some content</a>

在我的 main.js 中:

function openSomething() {

//this is where i think im going wrong
//ive tried window. and top. etc

var url = "http://www.google.co.uk/";

document.location.href = url

};

我对花式框的调用位于主页中。

任何帮助将不胜感激。

I'll try and keep this short. I have a page with various section. One section has an iframe with a google map in it. On the infowindows i have a link which when clicked i would like it to open in a fancybox over the page(not in the iframe...i can do that). For example if i had a link saying "google", id like it to open http://www.google.co.uk/ over the whole page in a fancybox.

I have 2 different pages and 2 javascripts, 1 for the map(iframe) and another for the main page. The function is in the main page script.

Where i think im going wrong is a) the right call to open the page b) attaching a class to the javascript i.e class="fancybox".

My map info window has this link in it(map.js):

<a href="javascript:parent.openSomething();">some content</a>

In my main.js:

function openSomething() {

//this is where i think im going wrong
//ive tried window. and top. etc

var url = "http://www.google.co.uk/";

document.location.href = url

};

My call to the fancy box is in the main page.

Any help would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懒猫 2025-01-14 19:58:17

无需使用 JavaScript:将所需链接设置为 href 属性,并使用 target 属性定义打开位置。

  • target="_top" 将在整个页面中打开新链接
  • target="_parent" 将在父框架或页面中打开它
  • target="_blank" 将在新窗口中打开它。

No need to use JavaScript: set the desired link as the href attribute, and use the target attribute to define where it is opened.

  • target="_top" will open the new link in the entire page
  • target="_parent" will open it in the parent frame or page
  • target="_blank" will open it in a new window.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文