Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I use relative URLs with IE7?

I've been Googling for a while and can't seem to find an answer to this question. My problem is as follows:

For my jquery, I need my links to be relative rather than absolute. My PHP is set to return relative urls and everything is working fine, until I test it in IE7. For some reason, IE7 keeps changing my relative urls to abosulute, which breaks my js script. Is this normal? Is there a way to get around it?

For example:

IE8, Chrome, Firefox, Safari etc -

<a href='/page' onclick='click_handler(this);return false;'>clicky</a>

IE7 -

<a href='http://www.myurl.com/page' onclick='click_handler(this);return false;'>clicky</a>
like image 298
gomezuk Avatar asked May 05 '10 15:05

gomezuk


1 Answers

What I do is grab the baseUrl at init, like:

var baseUrl = window.location.href.substring(0, window.location.href.lastIndexOf("/") + 1);

... and then in my URL handler, strip the baseUrl:

var url = $(this).attr("href").replace(baseUrl, "");

Also you can check if the href is "normalized" using .support():

$.support.hrefNormalized

(returns true if the browser makes no modifications when grabbing an href value, so it's currently false in IE.)

like image 100
JKS Avatar answered Oct 01 '22 00:10

JKS