0

Alright, I've coded my own CMS that's using jquery, php, .htaccess redirecting to one index.php behind the curtains, and HTML5 History API. Now I encountered weirdest bug I've ever seen.

On my computer, and on my android phone, and on most the devices I try, everything works flawlessly.

But then, on one of my friends computer AND iPhone, whatever browser I use, even the same newest chrome that I use myself, Dom Exception 18 happens (in javascript console), and stops all the ajax code from executing, breaking the CMS.

The error points to this row:

History.replaceState({location:href}, "", href);

Just a regular history.js statement that works flawlessly with my browsers. I actually used normal html5 history API but changed it to history.js implementation to see if it helped, it didn't. If I remove the initial replaceState, the error happens when I click any link, so it's the first history push event that's triggering the Dom error.

I've tried to search for Dom Exception 18, but all the answers seem to relate to specific packages or manipulating images from different hosts.

You can see for yourself if it works for you in www.roopesalminenjakoirat.fi. Dom Exception 18 should appear in the inspector immediately, if it happens. It doesn't break the page because I don't use ajax when logged out, but please report if you see the error.

Please help!

Qha
  • 49
  • 3
  • possibly related: http://stackoverflow.com/questions/2704929/uncaught-error-security-err-dom-exception-18-when-i-try-to-set-a-cookie – Raptor Jul 26 '13 at 02:40
  • Eh, woah, now it happened to my browser too. But only if I open the site from the link in this page. If I enter the address manually or refresh the page, it doesn't happen... :O – Qha Jul 26 '13 at 02:45
  • It's a security issue. Why do you want to use `History.replaceState()` ? – Raptor Jul 26 '13 at 02:57
  • I use the history API to navigate the state with modern touch, it loads content from hidden divs or ajax and changes the address bar accordingly. The first replaceState sets the initial state so that one can navigate back. It doesn't help if you remove the first replaceState. Then the DOM exception happens with your next pushState. – Qha Jul 26 '13 at 03:02
  • In your link, this is the only answer that's related to my issue: http://stackoverflow.com/a/16432523/1213272 It suggests to add http://, but I'm using relative links in the state objects so can't do that. – Qha Jul 26 '13 at 03:05
  • Alright, tried absolute links by merging my root url to the navigation, to see if State.url handles absolute urls better. Still throws DOM Exception 18 – Qha Jul 26 '13 at 03:14

1 Answers1

0

found it! Apparently it's got to do with base-element either having "www" or not. Currently I have just <base href="http://roopesalminenjakoirat.fi" />, so the problem didn't occur to me before because I usually don't type www, but occurred to my friend because he writes the www!

So the answer is to match the base-element www-part with whether the user has typed it or not, otherwise replaceState throws a security error!

Qha
  • 49
  • 3