March 30, 2006

Base HREF and Javascript Location.href with IE vs NN

You will find other articles relevant to this document in these sections:
Cameron Manderson @ 4:16 pm

Just having a play with some JavaScript to generate a URL to redirect the user to.It appears that IE does take into consideration your < base xhref="" mce_href="" > in your header when executing a location.href=”" mce_href=”" command with IE. It does however work with NN. In my scenario it was due to a having images and CSS work relative to a different folder, with operations occuring in a different folder. This was due to my templating setup.

Instead of simply calling:

location.href=”myotherfolder/?do=whichever”;

you can build the whole URL using

location.href = window.location.protocol + “//” + window.location.host + window.location.pathname + “myotherfolder/?do=whichever”;

which sidesteps your base href declaration in your head HTML. May be useful to keep in mind.

Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • digg
  • Furl
  • Reddit
  • YahooMyWeb

1 Comment »

  1. It is important that you allow use the window.location to build your URL as you may inadvertantly move a person from a different protocol (eg, from HTTPS to HTTP). You also want to leave it built from the URL as you will not have to worry about moving the contents of your site to a different domain or folder on your hosting space.

    Comment by Cameron Manderson — April 5, 2006 @ 5:59 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment