This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes html img problem with base url Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "html img problem with base url" Watch "html img problem with base url" New topic
Author

html img problem with base url

Mark Uppeteer
Ranch Hand

Joined: Mar 02, 2004
Posts: 159

Hi guys,

I have this simple problem with html that I can't seem to figure out.

I have a page with items, if you click on an item a popup shows.
This popup contains a html page with an image. The image is not shown. This is my problem.
Now I know why, but I don't know how to solve this.

The html page comes from another webapp. It is loaded with jquery into a div and shown as popup.
The problem is that the path to the image is relative.

So say the main page is http://A.com/myapp/home.html and this page shows in a popup the page
at http://A.com/myotherapp/page.html with therein the image with src="images/image.jpg " then the browser will look for this image at http://A.com/myapp/images/image.jpg instead of the
intended http://A.com/myotherapp/images/image.jpg


anyone knows how to solve this ?


I know there is a BASE tag that you can use in the header, but I dont want that since that would make it impossible to run the app in developent, test and production environment differently since I have to
put the complete url in there... I would like to put the base to "myotherapp" in the popup html page.

hope this isn't to confusing ;)

anyone knows how to solve this ?

best regards,
Mark

I know where my towel is. (SCJP 5, OCPJWCD)
[Free Quiz Tips for a fun night with friends or family] Flash games
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

Do you have control over the remote HTML page? If so, change the image URL to be server-relative (starting with the context path) rather than page-relative. Page relative URLs should always be avoided in web apps -- they're the kiss of death.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mark Uppeteer
Ranch Hand

Joined: Mar 02, 2004
Posts: 159

thanks for the answer and sorry for my late reply., the problem with that is that the pages need to be offline editable by dummy users...and they need to see images in the html files. Ideally i give them a zip they can just open with therein the images and html. They might change the html,or the images.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: html img problem with base url
 
Similar Threads
Accessing images from another path in UNIX
URL redirect
ServletFilter to allow/deny directory access -> save against "hackers"?
jQuery Galleria Photogallery problem in quirks mode
Mapping to local context root