简体   繁体   English

如何在不更改第一个js文件的情况下使用另一个功能向一个javascript程序添加功能

[英]How can I add functionality to one javascript program using another without altering the first js file

On the surface, this question seems easy (and admittedly I am new to javascript so it may be), but here are the details: 从表面上看,这个问题似乎很简单(诚然,我是javascript的新手,所以可能是),但是这里是细节:

The work I do is in Drupal, therefore I work predominately with CSS and Drupal's interface. 我所做的工作是在Drupal中进行的,因此我主要使用CSS和Drupal的界面进行工作。 However, for the current function I am doing, I need to use Javascript to add an overlay onto an existing Google map. 但是,对于我正在执行的当前功能,我需要使用Javascript将叠加层添加到现有的Google地图上。 I have already written the javascript, and the map is working, but the location of my javascript is inside the javascript of the module I am using to make the map. 我已经编写了JavaScript,并且地图可以工作,但是我的JavaScript的位置在我用来制作地图的模块的javascript中。 If I keep it there, then once the module updates, my work will be overridden by the new javascript. 如果我将其保留在该模块中,则一旦模块更新,我的工作将被新的javascript覆盖。 Therefore, what I need to do is add my functionality inside a new javascript file saved elsewhere that can effect the javascript inside the map module without having to write anything into the map module. 因此,我需要做的是将功能添加到保存在其他位置的新javascript文件中,这可以影响map模块内部的javascript,而无需在map模块中写入任何内容。 I have seen plenty on this that requires a call to be placed in the original js file, but that won't work, as it will be overridden on the next update. 我已经看到了很多有关此问题的信息,它要求在原始js文件中放置一个调用,但这将无法正常工作,因为它将在下一次更新中被覆盖。

You can easily add JS for specific view... 您可以轻松地为特定视图添加JS ...

function yourtheme_preprocess_views_view(&$vars) {
    $view = $vars['view'];
    // Make sure it's the correct view
    if ($view->name == 'your-view-name') {
        // add needed javascript
        drupal_add_js(drupal_get_path('theme', 'your-theme') . '/your-js.js');
    }
}

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

相关问题 如何将一个数组从javascript文件写入另一个新的js文件? - How can i write one array from javascript file to another new js file? 如何在不需要服务器交互或cookie的情况下将值从一个Javascript文件传输到另一个JS文件? - How do I Transfer values from one Javascript file to another JS file without the need of server interaction nor cookies? 从另一个 JS 文件替换 JavaScript 功能 - Replace JavaScript functionality from another JS file 如何在 javascript 中的另一个元素之后添加一个 HTML 元素? - How can I add an HTML element after another one in javascript? 如何在不使用 eval 的情况下使用 JavaScript 的功能来创建计算器? - How can I use JavaScript's functionality to create a calculator without using eval? 如何在不阻止功能的情况下编辑此Javascript? - How can I edit this Javascript without blocking functionality? 如何将数据从一个 js 文件访问到另一个文件? - How can I access data from one js file to another? 如何将 onClick 功能添加到 React Js 中的特定列? - How can I Add onClick functionality to particular column in React Js? 如何在60秒后将自动点击功能添加到按钮并使用javascript执行该操作? - How can I add automatic click functionality after 60second to button and perform that operation using javascript? 我如何在另一个js文件中获取javascript值 - How can I get javascript value in another js file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM