javascript - Stripe 自定义排版字体

标签 javascript stripe-payments webfonts cloud.typography

我的网络服务器上托管了一个 cloud.typography 字体。当我尝试使用 stripe.elements() 将它链接到 stripe 时,我的字体没有显示,它默认为 Helvetica。我也没有收到任何 javascript 错误。

这是我的javascript代码:

var elements = stripe.elements({
    fonts: [
        {
            cssSrc: 'localhost:8080/static/fonts/######/#################.css',
        },
    ],
});
var baseStyle = {
    fontFamily: 'Gotham Narrow A, Gotham Narrow B, sans-serif',
    fontSize: '16px',
    lineHeight: '1.5',
    fontWeight: '300',
    color: '#2d3138',
    '::placeholder': {
        color: '#8f95a3'
    }
};
var invalidStyle = {
    fontFamily: 'Gotham Narrow A',
    fontSize: '16px',
    lineHeight: '1.5',
    fontWeight: '300',
    color: '#e70000'
};
var style = {
    base: baseStyle,
    invalid: invalidStyle
};
var styles = {style: style};
var card = elements.create('cardNumber', styles);

如果我尝试使用它给我的 css 链接直接链接到排版,我会收到以下错误:

Failed to load https://cloud.typography.com/#######/#######/css/fonts.css: 
Redirect from 'https://cloud.typography.com/#######/#######/css/fonts.css' 
to 'https://myhostedwebsite.com/fonts/######/#################.css' 
has been blocked by CORS policy: No 'Access-Control-Allow-Origin' 
header is present on the requested resource. Origin 'http://localhost:8080' 
is therefore not allowed access.

我还尝试将我的字体导入为字体系列对象。

var elements = stripe.elements({
    fonts: [
        {
            family: 'Gotham Narrow A',
            src: 'url(https://myhostedwebsite.com/fonts/######/#################.eot)',
            style: 'normal',
            weight: '300',
        },
    ],
});

请帮忙。

最佳答案

编辑

@Michael 发现他必须将 stripe.com 添加到 cloud.typography 项目仪表板上的启用域列表中。现在 Stripe 元素使用的是 cloud.typography 字体。当使用 --disable-web-security 标志运行 chrome 时,这是有效的。但是,当使用 chrome 扩展程序时,这些结果不起作用。


你的错误说:

Failed to load https://cloud.typography.com/#######/#######/css/fonts.css: 
Redirect from 'https://cloud.typography.com/#######/#######/css/fonts.css' 
to 'https://myhostedwebsite.com/fonts/######/#################.css' 
has been blocked by CORS policy: No 'Access-Control-Allow-Origin' 
header is present on the requested resource. Origin 'http://localhost:8080' 
is therefore not allowed access.

Chrome 不支持本地主机的 CORS 请求。

您可以使用 Allow-Control-Allow-Origin: * Chrome 扩展来解决这个问题。该扩展将为 CORS 添加必要的 HTTP header 。

使用 --disable-web-security 标志启动 chrome

关于javascript - Stripe 自定义排版字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51735070/

相关文章:

javascript - 调用 FB Credits API 时出现错误 1151

javascript - 如何在不弄乱特殊字符的情况下将用户输入的值转换为正则表达式?

javascript - 使用 twitter bootstrap 切换按钮和面板

scala - Play 框架的 Stripe Webhook 验证错误

css - 快速字体网络字体在 chrome 或 ie 中不起作用

javascript - ES7 中新的 async 和 await 关键字是从 C# 复制过来的吗?

javascript - 如何根据 ajax 成功创建 Stripe token 的条件

php - 我使用这个 PHP 代码错了吗? (使用 Stripe )

css - 谷歌字体拉丁扩展不起作用

javascript - 如何检查客户端浏览器是否阻止了 font awesome?