简体   繁体   English

如何将OneSignal订阅链接(javascript)变成按钮?

[英]How can I turn an OneSignal subscription link (javascript) into a button?

I have the code for the CSS of the button and the subscription javascript of OneSignal. 我有按钮CSS的代码和OneSignal的订阅javascript。 The plain javascript just shows the text as a link, and I want to create a button instead, but when I try to put the CSS on the code it just seems like a highlight in the text and becomes so hard to click on it (it's clickable only on the top of the text). 普通的javascript只是将文本显示为链接,而我想创建一个按钮,但是当我尝试将CS​​S放在代码上时,它看起来像是文本中的亮点,并且变得很难单击(仅可在文字顶部单击)。

The OneSignal code is OneSignal代码是

 <body> <a href="#" id="subscribe-link" style="display: none;">Click here to subscribe</a> <script> function subscribe() { OneSignal.push(["registerForPushNotifications"]); event.preventDefault(); } var OneSignal = OneSignal || []; /* This example assumes you've already initialized OneSignal */ OneSignal.push(function() { // If we're on an unsupported browser, do nothing if (!OneSignal.isPushNotificationsSupported()) { return; } OneSignal.isPushNotificationsEnabled(function(isEnabled) { if (isEnabled) { // The user is subscribed to notifications // Don't show anything } else { document.getElementById("subscribe-link").addEventListener('click', subscribe); document.getElementById("subscribe-link").style.display = ''; } }); }); </script> </body> 

And my CSS code is 我的CSS代码是

 <head> <style type="text/css"> .subscribe-link { background: #F76A0C; width: 200px; text-align: center; float:right } .subscribe-link a { color: #fff; display:block; padding: 13px 0px; } .subscribe-link a:hover { color: #fff; background: #FA9450; } </style> </head> 

Is there other way to put the CSS on the code? 还有其他方法可以将CSS放在代码上吗? I really need to show a button instead of pure text. 我确实需要显示一个按钮而不是纯文本。 Thanks in advance. 提前致谢。

I believe you can define the html button with the id = 'subscribe-link' and remove the tag. 我相信您可以使用id ='subscribe-link'定义html按钮并删除标签。

<button id="subscribe-link" type="button">Click Me</button>

EDIT (add the screen-shot): 编辑(添加屏幕截图):

在此处输入图片说明

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

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