/    Sign up×
Community /Pin to ProfileBookmark

IE scope help

Well, it turns out ie8 has yet another problem. My code has a global variable (to the object) inside an object declaration that cannot be accessed by a function (that is also global). I was wondering if anybody had any thoughts on how to fix this little problem. I the code is like so:

[CODE]

function myobject(params)
{

//public
this.initialize = function(){…}

//private
some variables…
//problem variable
var mouse = new Object()
mouse.x = 0;
mouse.y = 0;

//code…
slidecontainer = document.createElement(“div”);
slidecontainer.onmousemove = function(event)
{

[INDENT]if(boo.isIE)
{

[INDENT]e = window.event;
mouse.x = e.x + document.body.scrollLeft;
mouse.y = e.y + document.body.scrollTop;[/INDENT]

}
else
{

[INDENT]e = event;
mouse.x = e.clientX + document.body.scrollLeft;
mouse.y = e.clientY + document.body.scrollTop;[/INDENT]

}[/INDENT]

}

//this function is in an interval
function moveslides()
{

/* this is where I have the problem
it seems that the function doesn’t recognize that mouse.x, or mouse for
that matter, exists. Mouse is global to the object, so why can’t this function access it? */
[INDENT]if(mouse.x)
{

code…

}[/INDENT]

}

}

[/CODE]

The page is at[URL=”http://www.technohawks.com/test/pictures.html”]http://www.technohawks.com/test/pictures.html[/URL] and works on every browser, including finnicky opera, except for ie. The full code is availabe when you right click and view the source on the page.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KorMay 10.2011 — In fact your code works in IE8 and IE9, but it does not work in FF4, nor in IE7. And I don't think your problem has something to do with that variable[B] mouse.[/B]

FF throws an error :" Error in parsing value for 'height'. Declaration dropped". That could be due to the fact that somewhere you might have set a style.height without specifying the measurement units, i.e. : "px"

Another thing: under an XHTML Doctype, the embedded script codes must be isolated inside CDATA island, to prevent an XML-like interpretation of some special characters:
<i>
</i>&lt;script type="text/javascript"&gt;
[COLOR="Blue"]/*&lt;![CDATA[*/[/COLOR]
[COLOR="Teal"]// code here[/COLOR]
[COLOR="Blue"]/*]]&gt;*/[/COLOR]
&lt;/script&gt;
Copy linkTweet thisAlerts:
@QazinoauthorMay 10.2011 — I added the cdata and the missing style.height measurement, but it still won't work. I tried debugging it in Chrome and Firefox, but I could not determine what was the matter. Do you have any ideas off the top of your head why it wouldn't work?
Copy linkTweet thisAlerts:
@KorMay 11.2011 — There is an error shown by Firebug in FF4:

"uncaught exception: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIDOMWindowInternal.alert]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://www.technohawks.com/test/hoverslideshow.js :: <TOP_LEVEL> :: line 492" data: no]

Line 0"
×

Success!

Help @Qazino spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...