简体   繁体   中英

How do I determine where this javascript is coming from?

So I've been handed an older website, and been asked to make some modifications. It's been made with ASP, and I'm not really familiar with it. http://www.littleairplane.com/who-we-are/default.aspx I've been asked to get rid of that awful scrolling.

By looking at the page source, I determined that the scrolling is done using some inline Javascript.

    <script type="text/javascript">

  function getElementPosition(theElement){
    var posX = 0;
    var posY = 0;           
    while(theElement != null){
      posX += theElement.offsetLeft;
      posY += theElement.offsetTop;
      theElement = theElement.offsetParent;          
    }                                     
   return {x:posX, y:posY};
  }

  var offsetY = 0;
  window.onload = function(){

    var elem = document.getElementById("foo");
    var elemPos = getElementPosition(elem);

    var box = document.getElementById("boxId");
    box.style.left = elemPos.x + "px";
    box.style.top = elemPos.y + "px";
    offsetY = elemPos.y;

    elem = null;
    box = null;

  }
  window.onscroll = function(){
    var scrollY = (window.pageYOffset)?(window.pageYOffset):(document.documentElement)?document.documentElement.scrollTop:document.body.scrollTop;
    var box = document.getElementById("boxId");
    box.style.top = (offsetY + scrollY) + "px";
    box = null;
  }

</script>

I would love to comment it out, but since it's ASP I'm not sure where to find that javascript. The default.ASP file I have doesn't contain it. And from what I can tell there is no call to an external .js file.

The only thing I could find was a java.htm file at the root which has the code I'm looking for, but It doesn't seem to matter whether or not that file is there.

So I'd like to know how to find that javascript. Any help is greatly appreciated.

Use FireBug and activate the Script tab.

There is a dropdown list of all the javascripts that are on the page, and their source paths.

If you run into source paths that contain "WebResource.axd?crazycrazystringofguidylookingstuff....", then you know that there are scripts being compiled into the dll as an embedded resource. Once you have the script text though, you can do a global find in your code to see where it's located.

Looks like it's been included somewhere... do a "Find..." for something like:

<!--#include

Also, it's kind of hacky, but you could set the window.onscroll event to null in javascript, at the very bottom of the master page?

You can step through asp in visual studio, if you have it. Alternatively you could try grepping through the code base. ASP surrounds its own code in tags (like JSP), so the javascript (or at least things other than specific element names) should be contiguous.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM