简体   繁体   English

使用Javascript从Drupal打开新标签页

[英]Open New Tab From Drupal Using Javascript

I am trying to open a new tab when a certain menu link is clicked in Drupal. 在Drupal中单击某个菜单链接时,我试图打开一个新选项卡。 One way I thought about doing is embedding a Javascript code within the content of that page. 我想到的一种方法是在该页面的内容中嵌入Javascript代码。 However, that does not seem to work. 但是,这似乎不起作用。

Specifically, I place this code inside the HTML content of that page: 具体来说,我将这段代码放在该页面的HTML内容中:

<script>

$(document).ready(function() {
  var popup  = window.open("about:blank", "_blank"); // the about:blank is to please Chrome, and _blank to please Firefox
popup.location = 'http://google.com';
});

</script>

Is there another way of achieving this? 还有另一种方法可以实现这一目标吗? To clarify, I still want the menu link to navigate Drupal to whatever page is assigned to it. 为了澄清,我仍然希望菜单链接将Drupal导航到分配给它的任何页面。 However, I also need a new tab to open upon the click. 但是,我还需要一个新选项卡才能在单击时打开。

A much easier method for what you are trying to do would be to install a module, such as Menu Target . 对于您尝试执行的操作,一种更简单的方法是安装模块,例如Menu Target In the menu item you want to be opened in a new tab you just need to click on the 'Open this link in a new window' checkbox. 在要在新选项卡中打开的菜单项中,只需单击“在新窗口中打开此链接”复选框。

There are other modules like Menu attributes , but I think the first one would work better for what you are trying to accomplish. 还有其他模块,例如Menu属性 ,但我认为第一个模块可以更好地完成您要完成的任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM