views:

174

answers:

2

Many of the web pages I am working on use files such as images and scripts that are mostly on a different domain from the page itself, so I put a base tag in the head of the page. For most purposes, this makes the site easier to work on. However, the page has a form, and I want to make the form submit to the same domain as the page. I would like to use a relative URL for the form action, so if we ever feel the need to move the page to a different domain, we would be able to do so easily.

The problem I am running into is that the browser (any browser I test the page in) is applying the relative URL to the base href, rather than the page domain. For example, if I have a site on the domain foo.com, and I have the base href set to bar.com, and the form action is "/submit", the form will submit to "bar.com/submit", when I am trying to make it submit to "foo.com/submit".

Does anyone know a way to make the browser ignore the base href attribute just for form submits? I have figured out ways to do it involving Javascript, which I can post if anyone cares to see them, but I am wondering whether there is a simpler way, without involving Javascript.

+2  A: 

There's no way to tell all browsers to ignore your base href for a particular relative url. Your javascript approach sounds good if you're okay with excluding users with javascript disabled. A server-side approach would be more fool-proof.

Ken Browning
A: 

can't do it in html. You could generate the full link on the server side (in php or whatever). If you generate it from the HTTP Host header it'll update when/if you move to a different domain.

JasonWoof