[FIXED] My website link from DJ Gold -- javascript error

To Report a Bug or Problem, start a New Topic.
We'll try and resolve the problem as quickly as possible.
(New feature suggestions should be posted in "Member Suggestions" above)

Moderator: Dave Miller

[FIXED] My website link from DJ Gold -- javascript error

Postby jwg » Wed Sep 15, 2004 4:30 am

Hey CJ - Just registered my site.

When a potential client would click on my site (which is built in frames), the fact that DJ Gold is the source of the link causes a 404 error.

I have a screenshot of it but can't seem to attach the image. I could email it to you...
User avatar
jwg
Gold Premium Member
Gold Premium Member
 
Posts: 1089
Joined: Wed Sep 15, 2004 3:56 am
Location: Erie, PA

Re: Error when clicking on my website link from DJ Gold

Postby CJ Greiner » Wed Sep 15, 2004 7:51 am

Hi John!

It looks like your website uses javascript to ensure that certain pages go where they're supposed to go.

I haven't taken a look... but it seems like either your main frames page is supplying a script that refreshes the content frame page based on the query url.

I haven't had a chance to look at the details of exactly what's happening, but I'll take a look at it this afternoon or evening.

Here's another way to look at your bug: Many search engines provide your server with more info than just the link. If there is no query string, you'll see them add the query with information after it.

If it's DJGold, your link looks like:
http://www.johngallagher.com/?source=DJGold.com


So if you want to see a different version of what your page is doing... simply add the (?) like this:
http://www.johngallagher.com/?

You’ll notice that in this case, if you click on that link, the content frame simply keeps on refreshing itself in your browser over and over and over again.

The script I’m finding on that content page is:
Code: Select all
<script language="javascript">
if(self.location==top.location)self.location="index.html?home.html";
</script>

It looks like that script is missing some info... (<!-- and -->) and relies on index.html?home.html running a script.

If your index.html is running as a script and doesn't know what to do with Query strings ( /?... ) that are not self-generated... that could cause a big problem for visitors that come to your site from other search engines!

Hmmm... I’ll look more at the problem later.
>> CJ Greiner
Website Administrator

Image
www.SmithfieldEntertainment.com
www.SilverStarDJs.com
User avatar
CJ Greiner
Site Owner
Site Owner
 
Posts: 2563
Joined: Thu Nov 28, 2002 11:21 am
Location: Smithfield, VA

Re: Error when clicking on my website link from DJ Gold

Postby CJ Greiner » Wed Sep 15, 2004 7:32 pm

Hi John,

I've been trying to look at your website... but it's been down for at least the last 1/2 hour.

----------

I suspect that it's the javascript code in both the main frames page, and the content pages.

I already know it's missing the <!-- and --> that's supposed to be there. I also suspect that it "assumes" that if there's a "?" in the url, then the info immediately following is a page name and nothing else.

Since that's not always true when getting click-throughs from search engines and other dynamically-created listing pages... I think you might need to update the code a little to get it to work right.

I'll see if I can make suggestions that will help you once your site is up again and I can see the code.
>> CJ Greiner
Website Administrator

Image
www.SmithfieldEntertainment.com
www.SilverStarDJs.com
User avatar
CJ Greiner
Site Owner
Site Owner
 
Posts: 2563
Joined: Thu Nov 28, 2002 11:21 am
Location: Smithfield, VA

Re: Error when clicking on my website link from DJ Gold

Postby jwg » Wed Sep 15, 2004 9:57 pm

Thanks CJ - always enjoy reading your posts.

My site is up now ?? Didn't realize there was a problem

I was on the road meeting a B&G at a halfway point between here and pittsburgh to go over their reception planner. Yes I will accomodate my clients for a higher rate - OOPS WRONG BOARD! lol.

I'll await the code I'd need to paste in from you and will upload it to my index.html or home.html page.
User avatar
jwg
Gold Premium Member
Gold Premium Member
 
Posts: 1089
Joined: Wed Sep 15, 2004 3:56 am
Location: Erie, PA

Re: Error when clicking on my website link from DJ Gold

Postby CJ Greiner » Wed Sep 15, 2004 11:04 pm

Hi John,

Your website came back up, so I spent some time working with the javascript in your main frames page: index.html

Here's what I found...

The code didn't account for anything other than exactly what you were expecting: a page name.

If anything else is there, it "crashes". That's a real problem for you because certain search engines and listing services add things to the end of your URL for tracking purposes... and whenever they do--your visitors won't see what you want them to see!

Here's the code in your index.html page:
Code: Select all
<script language="javascript">
var fname="content";
window.onload=function(){
var d=document.location.search;
if(d!='')top.frames[fname].document.location.href=d.substring(d.lastIndexOf('?')+1,d.length);
}
</script>


There are actually 2 problems with this code. The first is that it can't handle anything but exactly what it's expecting (as mentioned above).
The other problem is that it isn't properly "shielded" from browsers that don't properly utilize javascript. (We'll deal with this 2nd problem at the end of this post.)

First... lets re-write the code so that it can deal with almost anything after the query string:

Here's a common URL that a listing service might refer to you:
http://www.johngallagher.com/?source=li ... 6c3edf5073

Since the first info in the query (after the "?") isn't what the code expects... it crashes your main frame. How? Well it tries to send you to this page:
%3fsource=listingservice&sid=840bf63b5d3c522fa0aad46c3edf5073
(%3f == "?" in HTML)

... which of course, doesn't exist!

-----------------------
So, here's the solution: create a code that looks for the first value after the query (?), which in this case is: source=listingservice,
Then split it to find the first part before the "=" if it exists, which is: source,
Then decide if it's really a legitimate page by checking to see if it has ".htm" in it somewhere...
which it DOESN'T... so ignore it!!!

If it DOES, then follow it! Here's an example of one that does have a correct value that has been modified by a listing service:
http://www.johngallagher.com/?home.html ... 6c3edf5073

You can see the correct value after the "?" is home.html which of course IS an existing page on your server... but won't work with the existing code.

I took the liberty of loading a couple of your pages to an empty server I have, and modifying the code so that it works. Here's exactly the same link, but with the new code I wrote:
http://www.goldrack.com/?home.html&sour ... 6c3edf5073

... and it works!!!

(I'll delete your pages off of my server after 9/18/04)

Here's the code you need to replace the old code with:
Code: Select all
<script language="javascript">
<!--

var fname="content"; // name of your main content frame
var ename=".htm";    // minimum page ending for redirect

window.onload=function(){
  var d=document.location.search;
  if(d!=''){
    var thequery=d.split("?");
    var firstval=thequery[1].split("&");
    var thepage=firstval[0].split("=");
    if (thepage[0].indexOf(ename) != -1) {
      top.frames[fname].document.location.href=thepage[0];
    }
  }
}
//-->
</script>


NOTE: if the first element has ".htm" in the name then it will try to forward the user to it.
From the above example: home.html

You can always change it to just "." if you use your javascripts in pages that end in something other than ".htm" or ".html", or you can just contact me again and I'll modify the code to allow for the new page endings!
To change it, just change the line that looks like:
Code: Select all
var ename=".htm";    // minimum page ending for redirect

to
Code: Select all
var ename=".";    // minimum page ending for redirect


-------------------------
-------------------------

So... let's talk about the 2nd problem: browsers that don't understand javascript.
Most of them in use today do... but those that don't will actually show your javascript ON THE USER's SCREEN. (Unless you hide it!)

Here's how to hide it: Add "<!--" at the beginning of the script, and "-->" at the end of the script.
I did it in the above script for your main "index.html" page... but you'll also need to do it for all of your other pages that have the "no-frame-fix" scripts.

Here's that code as it is now in your weddings.html page:
Code: Select all
<SCRIPT language=javascript>
if(self.location==top.location)self.location="index.html?weddings.html";
</SCRIPT>


Here's how you should fix it:
Code: Select all
<SCRIPT language=javascript>
<!--
if(self.location==top.location)self.location="index.html?weddings.html";
//-->
</SCRIPT>


The "location" is different on each of your pages, so you'll have to go in and modify the "<!--" and "//-->" by hand on each page!

For more info on why you do this, see here:
http://www.javascripter.net/faq/hidingjs.htm

--------------------------
Let me know if you need help with any of this!

:idea:
>> CJ Greiner
Website Administrator

Image
www.SmithfieldEntertainment.com
www.SilverStarDJs.com
User avatar
CJ Greiner
Site Owner
Site Owner
 
Posts: 2563
Joined: Thu Nov 28, 2002 11:21 am
Location: Smithfield, VA

Re: Error when clicking on my website link from DJ Gold

Postby jwg » Wed Sep 15, 2004 11:25 pm

CJ:

Works like a charm now :) Many thanks for taking time out for the help!
User avatar
jwg
Gold Premium Member
Gold Premium Member
 
Posts: 1089
Joined: Wed Sep 15, 2004 3:56 am
Location: Erie, PA

Re: Error when clicking on my website link from DJ Gold

Postby CJ Greiner » Thu Sep 16, 2004 8:48 am

jwg wrote:CJ:

Works like a charm now :) Many thanks for taking time out for the help!


No problem!

It actually did take me a few hours of researching/writing/uploading/testing/etc. before I even had a chance to write my response to you...

That's because I'm really not a javascript programmer. (Yet.) Most of my experience is HTML, PERL and PHP.

javascript is a little different from standard programming in that you can have multiple functions that operate on a declared value all in a single line. It LOOKS more confusing than other programming styles because it was designed to be compact. In the days of 56k dialup... people wanted a programming language that would do a lot while not taking up a lot of bandwidth, so they ended up with code that looked like:
Code: Select all
if(d!='')top.frames[fname].document.location.href=d.substring(d.lastIndexOf('?')+1,d.length);
What the....???

Well since your problem came up, it forced me to learn a little bit about the language… and it really wasn’t so bad!

So… thanks for inadvertently assisting with my “programming education.”
>> CJ Greiner
Website Administrator

Image
www.SmithfieldEntertainment.com
www.SilverStarDJs.com
User avatar
CJ Greiner
Site Owner
Site Owner
 
Posts: 2563
Joined: Thu Nov 28, 2002 11:21 am
Location: Smithfield, VA


Return to Bug Reports

Who is online

Users browsing this forum: No registered users and 1 guest

cron