Javascript Not Implemented error - Stack Overflow

I am getting a Not Implemented error when trying to screen the screen-width into a hidden field on page

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;
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745226966a4617505.html

相关推荐

  • Javascript Not Implemented error - Stack Overflow

    I am getting a Not Implemented error when trying to screen the screen-width into a hidden field on page

    5小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信