Giter Club home page Giter Club logo

Comments (9)

oskameDEV avatar oskameDEV commented on August 22, 2024 1

https://en.wikipedia.org/wiki/Same-origin_policy
does describe it finds subdomains to be a different host than the original domain.

What were they thinking?!

Is there a workaround that can work with Barba?

from barba.

luruke avatar luruke commented on August 22, 2024 1

Hello @ideaprison .
This is not a problem of the ajax request, but a security limitation of the HTML5 PushState API.

From the documentation:

The new URL must be of the same origin as the current URL; otherwise, pushState() will throw an exception.

from barba.

oskameDEV avatar oskameDEV commented on August 22, 2024

Ugh, how idiotic..

Thanks for the fast respons though, at least I know what the problem is now.

from barba.

luruke avatar luruke commented on August 22, 2024

You may try some some crazy thing like:

  • Disable pushstate
  • Keep the new url in an hash (es. mystartsubdomain.site.com/#url=mynewsubdomain.site.com)

Then on the page load, if you detect the hash #url, redirect to that url.

Of course this would imply a fork of barba.js and modify some core functions like the onpopstate change and etc.

But it's the only way I think if you want to keep different subdomain.

Anyway it's strange that you have that error, ideally when barba.js can't do the pushstate should redirect to that url: https://github.com/luruke/barba.js/blob/master/src/Pjax/Pjax.js#L224

I will try to do some testing :)

from barba.

oskameDEV avatar oskameDEV commented on August 22, 2024

Oh, you're right it did forward to the page, I disabled your check to see if I could get it to work with the subdomain loading.

from barba.

smth avatar smth commented on August 22, 2024

@ideaprison did you pursue this any further? I was hoping to do something similar.

from barba.

oskameDEV avatar oskameDEV commented on August 22, 2024

There isn't a pretty workaround at this time. But depending on your transition animation.
You can edit the function in Barba.js so that any links that are detect not to be on the same domain will have a different transition. IE if you fade-in/out. You can then write your code to fade out the site, then load the subdomain, and have your site always load fading in. Because most browsers now hold the page while loading the next. So the transition (in this example fade-in/out) will look the same (but load less quickly then the pages on the same (sub)domain.

Hope I'm making sense.

from barba.

smth avatar smth commented on August 22, 2024

OK, thanks for letting me know. So if I'm understanding correcting, assuming you were only concerned with external links, there'd probably be no reason to include Barba in the above scenario. Right?

from barba.

oskameDEV avatar oskameDEV commented on August 22, 2024

Correct. Then you could just rewrite your links a bit with something like:

$('a.linkClass').on( "click", function(e) {
  $target = $(this).attr('href');

  showLoader();  // example function to show a transition.
  // Else do something like $('#content').fadeOut({
  //    window.location.href = $target;
  // }, 500);

  setTimeout(function(){
      // OPEN PAGE NOW
      window.location.href = $target;
    }, 2000); // timing depends on what you want to do for a transition.
  e.preventDefault();
});

from barba.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.