Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why is Javascript converting my absolute url to a relative one??? 2

Status
Not open for further replies.

Gert74

Technical User
Jan 26, 2001
48
0
0
NL
Hello,

I have an (in my opinion) awkward problem with Javascript. I include a file from a different site (actually it's a banner). The include banner contains images, and since they need to be displayed on a different domain I put the full path to the images in my Javascript. It looks like this:

.....
document.write ('<TD><A HREF=&quot;javascript:popitup();&quot;><IMG SRC=&quot; WIDTH=79 HEIGHT=60 ALT=&quot;Stembutton&quot;></A></TD>');
....

I include the file on the remote site like this:

<BODY>
...
<script language=&quot;Javascript&quot; src=&quot;...
</BODY>

The banner shows up correctly, but for some reason the &quot;<img src&quot; from the included file has been converted to a relative one, like this:
document.write ('<TD><A HREF=&quot;javascript:popitup();&quot;><IMG SRC=&quot;/salesportal/pix/stem.gif&quot; WIDTH=79 HEIGHT=60 ALT=&quot;Stembutton&quot;></A></TD>');

Which means it will look for the images on the site where the banner is included instead of the place where the banneris hosted. So no images show up.

Does somebody have a clue, because I am no Javascript hereo and I really don't know what the **** is going on here.

Greetz,
Gert




Gert
 
I tested this and I can't replicate the problem. I hope you find someone else who can help you out. :)
 
hi there

I have looked at your code and maybee you might want to consider making the following changes from your code:

document.write ('<TD><A HREF=&quot;javascript:popitup();&quot;><IMG SRC=&quot; WIDTH=79 HEIGHT=60 ALT=&quot;Stembutton&quot;></A></TD>');

here is what i would suggest why not just stick the &quot;popitup()&quot; launch command as a onlick comand and the get rid of the <a href> tags altogether like so adding the style option so that you get the hand as this is why you went for the <a href > tags i presume:

document.write ('<TD><IMG SRC=&quot; WIDTH=79 HEIGHT=60 ALT=&quot;Stembutton&quot; onclick=&quot;popitup()&quot; Style=&quot;cursor: hand&quot;></TD>');

I hope this helps you out.

cheers
dean
 
hi there

I have looked at your code and maybee you might want to consider making the following changes from your code:

document.write ('<TD><A HREF=&quot;javascript:popitup();&quot;><IMG SRC=&quot; WIDTH=79 HEIGHT=60 ALT=&quot;Stembutton&quot;></A></TD>');

here is what i would suggest why not just stick the &quot;popitup()&quot; launch command as a onlick comand and the get rid of the <a href> tags altogether like so adding the style option so that you get the hand as this is why you went for the <a href > tags i presume you want to make sure the full url is in for the image and the closing &quot; is there as it looks like it is missing on your code:

document.write ('<TD><IMG SRC=&quot; WIDTH=79 HEIGHT=60 ALT=&quot;Stembutton&quot; onclick=&quot;popitup()&quot; Style=&quot;cursor: hand&quot;></TD>');

simply copy and past this into yur page and past the correct url for the img src and this code should do the rest aslong as your java is in place.

I hope this helps you out.

cheers
dean
 
Hi,

Will check it out tomorrow when I'm back at work. Hope it works. Thanks for your help.

Gert

Gert
 
Well I tried it, but it didn't work. The header is still chopped off.

Any other suggestions??

Gert
 
o.k, before u do a document.write try giving an alert. it might be that HTML might be parsing the path. does the path in the alert also reflect this error?
alert('<TD><A HREF=&quot;javascript:popitup();&quot;><IMG SRC=&quot; WIDTH=79 HEIGHT=60 ALT=&quot;Stembutton&quot;></A></TD>');


Known is handfull, Unknown is worldfull
 
in my system the alert is working fine. can u give me the entire line (cut out the ...)...

Known is handfull, Unknown is worldfull
 
Ok, now it's not chopped off. So it seems that HTML is parsing the path, like you said. What's next?

Already thanks for your help by the way!

Gert
 
alert('SRC=&quot;
is displayed alright

alert('<IMG SRC=&quot; WIDTH=79 HEIGHT=60 ALT=&quot;Stembutton&quot;></A></TD>');

is displayed as:
<IMG SRC=&quot;/normenenwaarden/pix/stem.gif; WIDTH=79 HEIGHT=60 ALT=&quot;Stembutton&quot;></A></TD>

This is where it's all about:
document.write ('<TD><IMG SRC=&quot; WIDTH=79 HEIGHT=60 ALT=&quot;Stembutton&quot; onclick=&quot;popitup()&quot; Style=&quot;cursor: hand&quot;></TD>');

Gert
 
try:
alert('<TD><IMG SRC=&quot; WIDTH=79 HEIGHT=60 ALT=&quot;Stembutton&quot; onclick=&quot;popitup()&quot; Style=&quot;cursor: hand&quot;></TD>');

i got the correct value i the alert...

i tried the document.write and i found that u havent closed the &quot; after pix/..., please check that out too...

Known is handfull, Unknown is worldfull
 
I corrected the missing &quot;, thanks.

alert('<TD><IMG SRC=&quot; WIDTH=79 HEIGHT=60 ALT=&quot;Stembutton&quot; onclick=&quot;popitup()&quot; Style=&quot;cursor: hand&quot;></TD>');

Still returns:
<TD><IMG SRC=&quot;/normenenwaarden/pix/stem.gif&quot; WIDTH=79 HEIGHT=60 ALT=&quot;Stembutton&quot; onclick=&quot;popitup()&quot; Style=&quot;cursor: hand&quot;></TD>

Could it be a browserproblem. I have IE5.5
Checked it on Netscape 4.3, but the problem is the same overthere.

Gert
 
Hi VBKris and others,

I think I found the problem.
Due to the fact that I'm working at home with a remote connection with Putty and a tunnel, IE sees as my localhost or as my local drive when I'm starting the .html file up from my desktop.

I tried it out with a real remote site and guess what: I got a complete URL.

Thank you VBKris for your help. Without your help I guess I would have given up.

Gert
 
Hi gert

i am glad to see the bit of code i gave you is now working once you found the real problem.

i hope you find it useful and ontinue to use this simple approach why have two bits of code when one will do.

cheers

dean
 
You're right!

You know what? I give you a star too...

Gert
 
Heh - I like to just sit with this thread open so I can bask in the love. Can you feel it? ;oD
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top