最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript Not Implemented error - Stack Overflow

programmeradmin0浏览0评论

I am getting a Not Implemented error when trying to screen the screen-width into a hidden field on page load. Looking at other similar issues, they've all suggested putting everything in variables and making sure I wasn't using reserved words. I have and I am not (that I know of).

function GetScreenWidth() {
    var sWidth = screen.width;
    var hfSw = document.getElementById("<% =hfScreenWidth.ClientID %>");
    hfSw.value = sWidth;
}
window.onload = GetScreenWidth();

Originally, I was using

function GetScreenWidth() {
    document.getElementById("<% =hfScreenWidth.ClientID %>").value = screen.width;
}

Ultimately, I'm trying to get the screen-width back into the code-behind. If there are better ways to do that, I'd love to hear them.

EDIT: the hidden field is defined above the tag.

I am getting a Not Implemented error when trying to screen the screen-width into a hidden field on page load. Looking at other similar issues, they've all suggested putting everything in variables and making sure I wasn't using reserved words. I have and I am not (that I know of).

function GetScreenWidth() {
    var sWidth = screen.width;
    var hfSw = document.getElementById("<% =hfScreenWidth.ClientID %>");
    hfSw.value = sWidth;
}
window.onload = GetScreenWidth();

Originally, I was using

function GetScreenWidth() {
    document.getElementById("<% =hfScreenWidth.ClientID %>").value = screen.width;
}

Ultimately, I'm trying to get the screen-width back into the code-behind. If there are better ways to do that, I'd love to hear them.

EDIT: the hidden field is defined above the tag.

Share Improve this question asked May 30, 2013 at 21:30 TravisTravis 1,1051 gold badge17 silver badges37 bronze badges 1
  • What browser are you using? What line is throwing the error? Is it a server error or a JavaScript error? – Colin DeClue Commented May 30, 2013 at 21:34
Add a ment  | 

1 Answer 1

Reset to default 3

I've seen this error message under IE when setting unexpected values to event handlers. Basically, you're setting onload to a value of undefined (as that's what your function returns), which could cause all sorts of weird behavior. You probably want to bind a reference to GetScreenWidth to the event handler, like so:

window.onload = GetScreenWidth;

Or perhaps:

window.onload = function () {
    var sWidth = screen.width;
    var hfSw = document.getElementById("<% =hfScreenWidth.ClientID %>");
    hfSw.value = sWidth;
};

Or, if you happen to be using jQuery:

$(function () {
    var sWidth = screen.width;
    var hfSw = document.getElementById("<% =hfScreenWidth.ClientID %>");
    hfSw.value = sWidth;
});
发布评论

评论列表(0)

  1. 暂无评论