使用Javascript从Drupal打开新选项卡

时间:2022-09-12 08:30:13

I am trying to open a new tab when a certain menu link is clicked in Drupal. One way I thought about doing is embedding a Javascript code within the content of that page. However, that does not seem to work.

我想在Drupal中单击某个菜单链接时打开一个新选项卡。我想做的一种方法是在该页面的内容中嵌入Javascript代码。但是,这似乎不起作用。

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. However, I also need a new tab to open upon the click.

有没有另一种方法来实现这一目标?为了澄清,我仍然希望菜单链接将Drupal导航到分配给它的任何页面。但是,我还需要一个新标签,以便在点击时打开。

1 个解决方案

#1


0  

A much easier method for what you are trying to do would be to install a module, such as 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.

您尝试执行的操作的更简单方法是安装模块,例如Menu Target。在您想要在新标签页中打开的菜单项中,您只需点击“在新窗口中打开此链接”复选框即可。

There are other modules like Menu attributes, but I think the first one would work better for what you are trying to accomplish.

还有其他模块,如菜单属性,但我认为第一个模块可以更好地满足您要完成的任务。

#1


0  

A much easier method for what you are trying to do would be to install a module, such as 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.

您尝试执行的操作的更简单方法是安装模块,例如Menu Target。在您想要在新标签页中打开的菜单项中,您只需点击“在新窗口中打开此链接”复选框即可。

There are other modules like Menu attributes, but I think the first one would work better for what you are trying to accomplish.

还有其他模块,如菜单属性,但我认为第一个模块可以更好地满足您要完成的任务。