无法访问另一个CoffeeScript文件中的功能?

时间:2018-09-01 19:25:04

标签: google-chrome-extension coffeescript

我需要将src中的图像background.coffee设置为另一页,但是当我从backround.coffee调用该函数时,会得到view.setScreenshotUrl is not a function

//background.coffee
views = chrome.extension.getViews()
for view in views
    if view.location.href is viewTabUrl
        view.setScreenshotUrl screenshotUrl
        break

//page.coffee
setScreenshotUrl = (url) -> 
    document.getElementById("target").src = url

1 个答案:

答案 0 :(得分:1)

我将函数添加到窗口对象中,如下所示:

window.setScreenshotUrl = (url) -> 
    document.getElementById("target").src = url