javascript - 从类文件调用 JavaScript
问题描述
我尝试从浏览器发送通知。当我使用 aspx 页面中的代码时,它运行良好,但是当我将它放入类文件中的函数时,它不起作用。
这是我的代码:
public static void browserNotification(string title, string desc, string url)
{
string code = "";
code = @" {
if (Notification.permission !== 'granted') {
Notification.requestPermission();
}
});
function customnotify(" + title + ", " + desc + ", " + url + @") {
if (Notification.permission !== 'granted') {
Notification.requestPermission();
}
else {
var notification = new Notification(title, {
icon: 'http://SilenceMusicSchool.com/image/logo_icon.jpg',
body: desc,
});
/* Remove the notification from Notification Center when clicked.*/
notification.onclick = function () {
window.open(url);
};
/* Callback function when the notification is closed. */
notification.onclose = function () {
console.log('Notification closed');
};
}
}";
customnotify(" + title + ", " + desc + ", " + url + ");";
System.Web.HttpContext.Current.Response.Write("<script type='text/javascript'>" + code + "</script>");
}
我想在 aspx.cs 中调用函数:
Classes.browserNotification("a title", "a body", "url");
解决方案
推荐阅读
- java - 将 Datastore 实体导入 Eclipse 模拟器
- javascript - 为什么变量在 Javascript 中保持不变?
- pandas - pandas_profiling 运行时间过长
- kubernetes - 如何在没有云提供商或 LB 的情况下获取 pod 内的客户端 ip
- javascript - 按下按钮后使用javascript打开表单
- firefox - 如何在firefox上使用javascript转换功能画中画
- java - 即使在 HotSpot 中没有带有 CMS 的 Full GC 的情况下,Old Generation 的大小如何减小?
- solr - 如何在 Hybris 的 Solr 更新中跳过坏文档
- grafana - InfluxDB 时间落后 15 分钟
- sql - 如何在Oracle中按日期分组和排序?