• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Odd jscript problem

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Odd jscript problem

    Just found some kid's games I did a few years ago don't work in Chrome or Opera anymore, although still ok in IE and Edge.

    Narrowed it down to variables x,y being treated as style properties. This does not work as x, y have no values inside the with:

    x = e.pageX - x0; y = e.pageY - y0;
    with (imgs[n].style)
    {
    if (x>=pos(left))
    {
    blah blah

    Whereas this is ok:

    xx = e.pageX - x0; yy = e.pageY - y0;
    with (imgs[n].style)
    {
    if (xx>=pos(left))
    {
    blah blah

    Can't find anything in CSS style lists to suggest x is a style property. Gotta go through a whole lot of code and change x,y to summit else now. Is it usual for some browsers to invent their own properties and, if so, any lists? Ta.
    Last edited by xoggoth; 9 March 2018, 11:56.
    bloggoth

    If everything isn't black and white, I say, 'Why the hell not?'
    John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

    #2
    with statement is deprecated.

    but looking at the code, I'm assuming x and y are properties of the argument passed into the with statement "imgs[n].style".

    Comment


      #3
      Cheers woohoo. Didn't know it was deprecated. Scripts are a few years old.

      Doesn't explain why x,y are treated as style properties though, nothing in my jscript or html to account for it.

      Fortunately, they all seem to be working again after just changing x,y to xx,yy.
      Last edited by xoggoth; 9 March 2018, 18:16.
      bloggoth

      If everything isn't black and white, I say, 'Why the hell not?'
      John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

      Comment


        #4
        I’m guessing from looking at it that you are passing an image style to the with command.

        The with command changes the scope of variables. So it will look at any properties on the passed argument first.

        So again guessing here cause I can’t debug, but I imagine theire are properties x and y on the passed argument style.x and style.y.

        They may have been introduced on new versions etc.

        All just guesses and may be why with is deprecated.

        Comment


          #5
          There's an easy way to list properties or attributes here https://stackoverflow.com/questions/...-in-javascript

          Found that style does not have undocumented properties x and y, but img does have x and y attributes. So why did img.style get empty x,y when they are image attributes?

          You are right W, with does not work as I expected, in Chrome anyway! Cheers.
          Last edited by xoggoth; 10 March 2018, 10:51.
          bloggoth

          If everything isn't black and white, I say, 'Why the hell not?'
          John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

          Comment

          Working...
          X