Do I have to update all hrefs and src when doing pushState?

If I'm going to call pushState, but I want to keep all the relative links, images, style sheets, etc., I am doing something like this so far:

$('[href]').each(function() { 
    if (!/^#/.test(this.href)) this.href = this.href;
});
$('[src]').each(function() { this.src = this.src });

My question is: will this work with cross browser? Do I need to do $(this).attr('href') = this.href?

It's necessary? Is there any other way to do this? Is this the best way to do this? And will he always work?

+3
source share
1 answer

pushState changes the relative path of the current document.

You can break or avoid breaking relative sources depending on how you relate the path.

./* , /* pushState.

./this/would/break.jpg

/this/wont.jpg
+3

All Articles