Tag Archive for: eBay Scroll Bars

That’s How You Solve Scroll bars in eBay Listings! – Fix eBay’s Duff Code

I covered this previously in an article called “Do you keep seeing scroll bars on your eBay listings?” and as I started to explore this again for someone it became apparent that eBay’s JavaScript code is actually broken.

But before we go any further, I am fully aware that this could be classed as “site interference” by eBay (again this a debatable subject, as I’d class it as fixing a known problem, hence the following notice), so this comes with an explicit warning not to use this code, but for eBay to pick up this article and relay it to the right department (as I know you read this site *coff*).

Unpicking the Code

In the comments of the earlier article “Do you keep seeing scrollbars on your eBay listings?” I soon worked out why the scrollbars were appearing, the height attribute was not being assigned back to the page correctly.

eBay pass a variable in the URL of the item being viewed, I’m sure you have seen it before it looks like “#ht_1480wt_1396″at the end. What this is, is the height at 1480 and the width at 1396.

Now eBay have got the code in a subfunction called “ifr.getSize = function (some code here) “. This function gets the width really well and I have never seen an issue with the width on an eBay listing that has not been the code the seller made.

The code looks like this:

if (document.all) {
h = document.body.scrollHeight;
w = document.body.scrollWidth;
if (oCl.bIE && oCl.iVer >= 9 && document.getElementById('EBdescription')) {
h = document.getElementById('EBdescription').scrollHeight;
var u = document.location.href;
if (u && u.indexOf('&tid=') != -1 && document.getElementById('ngvi_store_id')) {
h = document.getElementById('ngvi_store_id').scrollHeight;
}
h = h + 40;
}
} else {
h = document.body.offsetHeight;
if (oCl.bSafari && oCl.iVer >= 523) {
w = document.body.scrollWidth;
} else {
w = document.body.offsetWidth;
if (window.scrollMaxX !== 0) {
w += window.scrollMaxX;
}
}
}

The line in bold works really well as most listings have a normal width “w = document.body.scrollWidth;“. But the function to get the height, well that’s forked, AKA broken.

And the problem is really obvious now, the code to set the height is trying to get the height straight away and in that attempt lies the problem, you can’t get the accurate height of a page if it’s not loaded yet!

I’d also like to point out at in the code that is in the iframe, eBay has gone for the right DIV tag, but forgotten to add an ELSE statement after it with some extra code to grab the other event, ie what happens if ngvi_store_id is not found?

So to the function that gets the page sizes (“ifr.getSize”) needs to be slowed down by a few seconds to let the iframe contents (that’s your descriptions) actually load.

Using something like this would work well:

setTimeout("ifr.getSize()", 5000);
rest of the code

But we don’t have control over that code, so the way to get around this is to add a delay and then force the parent URL of the listing to have new values for “#ht_” and “wt”.

About 5 seconds to be precise, plenty enough time for the entire description to have loaded and then send back the correct height to the eBay handler so that the scroll bars go away, because we now what the correct height actually is and have not been so eager to fix the page height.

<script type="text/javascript">
setTimeout("FixMyListingHeight()", 5000);
function FixMyListingHeight(){
var rf = window.document.referrer;
if (oCl.bSafari && oCl.iVer >= 523) {
w = document.body.scrollWidth;
} else {
w = document.body.offsetWidth;
if (window.scrollMaxX !== 0) {
w += window.scrollMaxX;
}
}
h = document.body.scrollHeight;
parent.location.replace(rf + '#ht_' + h + 'wt_' + w);
parent.frames[0].location.replace(sUrl + '&c=' + callerId + '#ht_' + h + 'wt_' + w);
}
</script>

This code is not perfect, but it works on IE, FF and Chrome. In FF the height get’s over-amplified, in this case, it’s a good problem, it just means it’s a long page to scroll through to ask a question :)

What it is missing is some specific code to catch the different browser versions as they appear to report back the height incorrectly across the browsers. That’s beyond my coding skills, I’m just pointing out what the issue is [it needs to be slowed down] and now how to solve it :)

Thought I’d share that with you, as the silly scroll bars have been driving me nuts for months.