homepage Welcome to WebmasterWorld Guest from 54.226.161.112
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Problem with javascript in netscape
Robber




msg:1480959
 10:42 am on Jul 18, 2002 (gmt 0)

Ive got a javascript in my head section which does some work based on data pulled out of a cgi script. I am trying to place this into the webpage with another javascript at the insertion point which uses a function call to get the data. So basically the script in the head takes some variables and joins them all up in a document.write. This is then called from the other script. This works fine in IE but Netscape seems to have a problem with the document.write being in a separate script. Anyone know how to overcome this?

Cheers

 

joshie76




msg:1480960
 10:55 am on Jul 18, 2002 (gmt 0)

Can you post the code?

Robber




msg:1480961
 11:02 am on Jul 18, 2002 (gmt 0)

Hi Joshie,

It goes like this:

This is the script in the head:

function displayBanner(){
var imageURL=image;
var linkURL=link;
writeImage(linkURL, imageURL);
}

This is the one in the body:

displayBanner();
function writeImage (linkURL, imageURL){
document.write('<a href="'+linkURL+'"><img src="'+imageURL+'" border="0" width="125" height="125">');

}

Cheers

joshie76




msg:1480962
 11:16 am on Jul 18, 2002 (gmt 0)

Is
displayBanner() called before the writeImage() function is written in the source?

Do you know what the error is? (type javascript: into the address bar just after the error occured).

edit>>DOH! I can see that your displayBanner() function is called before the writeImage function exists and think this may be the cause of your problems...
can you try:

function writeImage()
{
...
}
displayBanner();

Robber




msg:1480963
 11:22 am on Jul 18, 2002 (gmt 0)

I tried that but thats not it. I think my function names may be a little misleading. The displaybanner function assigns values to the variables based on values taken from the cgi. The writeImage function takes these values and concatenates them into a hyperlinked img. It works great for IE but netscape doesnt output anything, and also doesnt suggest there are any errors. Confusing huh!!

Sinner_G




msg:1480964
 11:30 am on Jul 18, 2002 (gmt 0)

Is there a reason you have this in 2 different functions and not something like this?

function displayBanner(){
var imageURL=image;
var linkURL=link;
document.write('<a href="'+linkURL+'"><img src="'+imageURL+'" border="0" width="125" height="125">');
}

Robber




msg:1480965
 11:34 am on Jul 18, 2002 (gmt 0)

Hi Sinner, thanks for chipping in. Funny you should say that, thats what I started with, but I wondered if that could be the problem so I changed it - but it still didnt work.

Cheers

Sinner_G




msg:1480966
 12:05 pm on Jul 18, 2002 (gmt 0)

Robber, I just did a local test page with just the one function. Just had the image and link URLs directly in the function and not from a cgi. And it worked perfectly well (NS 4.7 and NS7.0 preview), so maybe the problem is in you cgi?

Robber




msg:1480967
 12:10 pm on Jul 18, 2002 (gmt 0)

Thanks for the test sinner - I think you might be right. I just did a similar test except pulled the data out of a diferent cgi and it seemed to work fine. Seems to be reading another part of the cgi when in Netscape even though I've got an exit statement in their - but I guess thats another problem now - I best bury my head in a book.

Cheers

Robber




msg:1480968
 12:37 pm on Jul 18, 2002 (gmt 0)

Does anyone know if Netscape has a problem with putting a cgi as the src of a javascript?

edit>>
Just in case anyone is following this - netscape seemed to have a problem with the cgi script. The cgi was outputting under a javascript mime header as part of a subroutine but netscape was trying to read the whole cgi for some reason (no idea why). So I put that sub into its on cgi doc and it works fine now.

joshie76




msg:1480969
 12:58 pm on Jul 18, 2002 (gmt 0)

Netscape would have no way of knowing the JS came from CGI, the CGI is just delivering *normal but dynamic* text source to the browser.

Maybe you could show us some of the generated source (with the CGI output)or stickymail me the URL.

Robber




msg:1480970
 1:11 pm on Jul 18, 2002 (gmt 0)

Im just trying to upload it to a public server so you can take a look - trouble is, its broken in IE now!! I'll let you know when we're up and running.

Cheers

Robber




msg:1480971
 1:34 pm on Jul 18, 2002 (gmt 0)

I think I know what the problem is, but I dont really know why I get it. In the cgi I have a part that checks the referer, this is both for security and to tell the script what to do depending on who the referer is. I think that in netscape this part is breaking down so the sub with the javascript stuff in it isnt executing - hence why I get my variable being undefined.

Does Netscape have a problem with HTTP_REFERER?

joshie76




msg:1480972
 2:31 pm on Jul 18, 2002 (gmt 0)

Personally I wouldn't rely on the HTTP_REFERER as, just looking in my logs I see total nonsense all the time.

I don't know but maybe NS4 doesn't pass the referer to file in the <script src="cgi" ... />, perhaps a QueryString could solve your problem, eg:

<script src="cgi-bin/myfile.pl?mode=js" ... />

Robber




msg:1480973
 2:49 pm on Jul 18, 2002 (gmt 0)

Thats an idea, I guess the only problem is that people could manipulate the script easier then. I had figured that if I used the HTTP_REFERER then I could verify that all requests to the cgi were from a page on my site. Perhaps its not the best way, I'll give your suggestion a go.

edit>>> Oh, and BTW, its not just NS4, NS^ does exactly the same. I tried just printing the referer and its empty for both.

Cheers

Robber




msg:1480974
 3:04 pm on Jul 18, 2002 (gmt 0)

Finally, I have cracked what the problem is - and it seems so simple now. I think Netscape only tracks the HTTP_REFERER if someone actually clicks a link - not if the url is say an img or javascript src. Well that explains it. Just tested this with a simple text link and the HTTP_REFERER is tracked in IE and NS so that would appear to be the problem.

Hope someone finds that useful!

Cheers

tedster




msg:1480975
 5:16 pm on Jul 18, 2002 (gmt 0)

That's very useful. It may explain some long-standing strangeness for me. Time to go digging.

Thanks!

Robber




msg:1480976
 5:52 pm on Jul 18, 2002 (gmt 0)

No problem tedster, Im glad all my problems are of some use. You never know, I'll probably post another one tomorrow!!

Cheers

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved