Javascript函数GetChatURL未定义
Javascript Function GetChatURL is not Defined
所以这些定义问题通常与语法有关,但我没有看到我的语法错误。我的问题是,为什么我的函数没有定义,当我有它定义的onload?
我试图改变这个链接的onclick事件打开一个URL与一些值我没有,直到运行时。下面的所有代码都包含在body标签中。
HTML
<a id ="chaturl" style="position: fixed; top: 55%; right: 0; height: auto;" href="http://someurl" target="_blank" onclick="GetChatURL()"><img alt="Chat" src="~/Content/images/check.png" border="0"></a>
这里是一个misc RenderSection位于
之间@RenderSection("scripts", required: false)
这是JS
<script type="text/javascript">
window.onload = function () {
document.getElementById("chaturl").onclick = function GetChatURL() {
var firstName = @(System.Web.HttpUtility.UrlEncode((User as OneStop.Core.Entities.Principal).User.FirstName));
var lastName = @(System.Web.HttpUtility.UrlEncode((User as OneStop.Core.Entities.Principal).User.LastName));
var email = @(System.Web.HttpUtility.UrlEncode((User as OneStop.Core.Entities.Principal).User.Email));
var phone = @(System.Web.HttpUtility.UrlEncode((User as OneStop.Core.Entities.Principal).User.PhoneNumber));
return "window.open(http://someurl/chat.aspx?firstname=" + firstName + "&lastname=" + lastName + "&email=" + email + "&phonenumber=" + phone + ", 'Chat', 'toolbar=no,location=no,directories=no,menubar=no,status=no,scrollbars=no,resizable=yes,replace=no');this.newWindow.focus();this.newWindow.opener=window;return false;";
}
}
</script>
首先,函数不应该返回 URL,而应该打开 URL。
此外,不需要将函数称为GetChatURL。把
document.getElementById("chaturl").onclick = function GetChatURL() {
document.getElementById("chaturl").onclick = function () {
或者,您可以单独定义该函数,然后需要将其更改为:
document.getElementById("chaturl").onclick = GetChatURL;
,然后定义函数:
function GetChatURL() {
var firstName = @(System.Web.HttpUtility.UrlEncode((User as OneStop.Core.Entities.Principal).User.FirstName));
var lastName = @(System.Web.HttpUtility.UrlEncode((User as OneStop.Core.Entities.Principal).User.LastName));
var email = @(System.Web.HttpUtility.UrlEncode((User as OneStop.Core.Entities.Principal).User.Email));
var phone = @(System.Web.HttpUtility.UrlEncode((User as OneStop.Core.Entities.Principal).User.PhoneNumber));
window.open("<url>")
}
相关文章:
- 为什么“;未定义的“;在JavaScript中结束循环
- 要求未定义JS回调参数
- 如何检查管道中未定义的项目
- TypeError:无法读取属性'推'未定义的JavaScript
- $window.ga在AngularJS事件中未定义
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 无法获取属性'selectedIndex'的未定义引用或null引用
- 如何消除代码中的未定义和其他问题
- 未捕获的ReferenceError:$未定义
- this.router在AngularJS 2中未定义
- 未捕获的类型错误:无法读取属性'删除'的未定义
- 节点fs.stat名称未定义
- 尝试在PHP中回显输入文本时出现未定义的索引错误
- Jquery未定义函数正在停止其他操作
- AngularJS指令出错-无法读取属性'编译'的未定义
- 这.SOMETHING 总是返回未定义的 - extjs
- 无法获取属性'Id'使用Knockout.js的未定义或空引用API
- Wordpress中带有JQuery Accordion的未定义匿名函数
- Javascript函数GetChatURL未定义