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
1 Answer
Reset to default 3I'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
评论列表(0条)