Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

<img> tags that use full URL are corrupted when the page is located in a subdirectory and <base> points to a different directoy #4195

eugenebond opened this Issue Apr 24, 2012 · 4 comments


None yet
5 participants


The page is located in subfolder/ and has base pointing to
There is an image that points to a full-path location

What happens is that the code below takes this full image path and removes the base part, turning it into
and then applies the new fake base URL
turning it into
which doesn't point to a real image

page.find( "[src], link[href], a[rel='external'], :jqmData(ajax='false'), a[target]" ).each(function() {
                        var thisAttr = $( this ).is( '[href]' ) ? 'href' :
                                $(this).is('[src]') ? 'src' : 'action',
                            thisUrl = $( this ).attr( thisAttr );

                        // XXX_jblas: We need to fix this so that it removes the document
                        //            base URL, and then prepends with the new page URL.
                        //if full path exists and is same, chop it - helps IE out
                        thisUrl = thisUrl.replace( location.protocol + '//' + location.host + location.pathname, '' );
                        if( !/^(\w+:|#|\/)/.test( thisUrl ) ) {
                            $( this ).attr( thisAttr, newPath + thisUrl );

This is a rather common problem on sites that use SEO URLs where subfolder/ is in reality page=subfodler. I don't fully understand the logic here, i.e. why do we need to modify img-s pointing to full-path URLs so I would appreciate if anyone could confirm and help with this bug.

PS. If subfolder/index.html is accessed, everything works fine though

@ghost ghost assigned jblas Apr 28, 2012

@ghost ghost assigned johnbender Sep 18, 2012


johnbender commented Apr 10, 2013


It seems like this is just a matter of ignoring urls that include the protocol. Is that accurate?

Yeah, that would work I think. I didn't have the full picture of how jQuery Mobile functions so didn't risk applying this fix myself because I was afraid to break something else. But yeah, ignoring protocol URLs is the first thing that comes into mind and is the way I would fix it.


ldeluca commented Oct 24, 2014

@eugenebond @johnbender There hasn't been any activity on this issue in over a year. We're in the process of cleaning up old issues. Can you confirm whether or not this is still an issue with the latest jQM or if we can go ahead and close? Thanks


arschmitz commented Oct 29, 2014

Im going to close this as stale i believe this was fixed along with some other base issues in 1.4

@arschmitz arschmitz closed this Oct 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment