Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search

TempusInfernus

Circle Member
  • Posts

    14
  • Joined

  • Last visited

Everything posted by TempusInfernus

  1. OK, apologies, that had me confused. Though, I'm not sure how helpful the URL to my site will be, as the the code I wrote here based on what you said in your first comment isn't live on the site because when I tried it, it didn't seem to work, but I did put what I had tried into a code quote comment here changing the name of the function from "customCode" to "pageRedirect" It's pretty simple - it's just a bunch of different page redirects. window.location.href being passed the variable of "url" for multiple placeholder pages It's probably not the best way to do it, but it's the only way I know how I could "get there" to have that kind of menu navigation...
  2. Huh? I specifically provided my site URL multiple times in this thread, in both posts and in the code I provided that is live on my site... AND in the hypothetical code I wrote based on what you mentioned here... To reiterate - it's goldenhourgraphics.com Since I specifically said less than 24 hours ago and only one comment before you replied that I didn't provide my site url... I'm not understanding why you would say that I didn't provide my site URL - it's right there.
  3. <script type = "text/javascript"> var url = "https://www.goldenhourgraphics.com/a-page-on-the-site"; function pageRedirect() { window.location.href = url; } document.write("Navigating to the correct page"); setTimeout('pageRedirect()', 0); </script> This is what is in the code blocks on each page. According to what you posted above... I would interpret what you said to mean that what I should inject into the overall headers across the site would be this: <script type = "text/javascript"> document.addEventListener('DOMContentLoaded', pageRedirect); window.addEventListener('mercury:load', pageRedirect); function pageRedirect() { /* Init the js code here */ var url = undefined; function pageRedirect() { window.location.href = url; } document.write("Navigating to the correct page"); setTimeout('pageRedirect()', 0); } </script> But it doesn't work at all and I have no clue what I am doing wrong or how to properly initialize the variable there. javascript n00b here.
  4. I tried that (the exact code you posted here) but nothing seemed to happen... It didn't work at all. ( I put it into the header injection for the whole site ) The part I don't know how to write is the "customCode" function which you left unwritten here. The question I am asking is how to write a function that calls a different variable every single time it is called over and over from a different page (as part of a code block) where I want the function to do something different each time... e.g. I want the page to redirect differently each time, and not at all the first time it's called which would be on the homepage. Basically I don't know what that "customCode" function should look like. Also do I put the ENTIRE thing into the code blocks ALSO? - including the document.addEventListener('DOMContentLoaded', customCode); window.addEventListener('mercury:load', customCode); parts... or just the function itself? (in script tags) I tried writing a function to do this, setting a variable of "url" and setting it as undefined for the first init, and then setting it in the code blocks but that didn't work at all. Nothing happened, and the page acted as if it didn't bother to load it at all. I finally gave up and disabled AJAX. The site is www.goldenhourgraphics.com Everything under the "View by Client Type" is all done with redirects as I couldn't build a 3rd level of navigation because Squarespace (kind of embarassingly) doesn't offer this very common 3rd level of flyout navigation. So I had to make landing pages as an intermediary step and use redirects.
  5. Squarespace AJAX page loading kills scripts on page. They will not load without a page refresh. Code written to every page initialized with the redirect value will just cause a redirect loop... How do I write a script that doesn't redirect the page initially that is in the header and LISTENS for an AJAX page refresh... and THEN gets reinitialized with a new value to redirect the page? (I've actually asked this question already but my posts aren't getting answered at all, so I'm starting to wonder what the coding and customization board is for if one can't ask a coding and customization question...)
  6. My understanding is that I cannot simply insert code into the header or a code block because my squarespace 7.0 template (jasper jin) uses AJAX and so does not reload the page. I like the AJAX, I don't want to disable it. How do I set up an event listener or something to make it so that a code block or header script tags WILL be fired when that part of the page loads? I don't want to disable ajax and I'm not an javascript expert but this seems like it should be simple code if I can get it to work even once. Any AJAX experts that can tell me how to write this basic two-part script... ?
  7. Something like window.location won't work because of the squarespace AJAX mercury loader not being coded to check for new javascript when there is a page change and I am not a javascript expert but with a little help might be able to implement something... Is there a way to set up a site-wide event listener so that I can trigger an individual page to redirect via either a page specific header injection or an event in a code block?
  8. So what I have gathered is that I actually need to so some kind of sitewide code injection to set up a listener for when there is any kind of an AJAX refresh which will reinitialize the function... The problem is that the function I want is a page redirect... So I understand THIS code is what I would want as part of a SITEWIDE code injection... continued below... <script> (function() { // Establish a function that does stuff. var myFunction = function() { // Do stuff here. }; // Initialize the fn on site load. myFunction(); // myFunction2(); , etc... // Reinit. the fn on each new AJAX-loaded page. window.addEventListener("mercury:load", myFunction); })(); </script> But what I am NOT sure about as I am in no way any kind of javascript expert... (or even novice) is what myFunction should be if I am going to be doing a different page redirect by doing "Page Header Code Injection" on individual pages. I have come to understand an effective way to do a page redirection might be <script> setTimeout(function(){ window.location.href = 'https://example.com'; }, 3); </script> but I would NOT want to perform a redirect on the initial site load (since the listener looking for mercury load would be on every page) Any help here is greatly appreciated.
  9. I should mention that I am doing this in a specific "Page Header Code Injection" but when I load the page and view source... I don't even see this code... I have definitely saved the page. Has page header code injection been removed from SquareSpace but the menu option still exists or something?
  10. <script> window.Squarespace.onInitialize(Y, function() { location.assign("https://www.squarespace.com"); } ); </script> If I inject this code into the header of a page, shouldn't the browser be directed to squarespace.com...? Nothing happens... Any ideas why? Is my code wrong?
  11. This is driving me CRAZY. I just want two little icons side by side in the footer that don't become HUGE on mobile. How damn hard does this have to be?
  12. You can run javascript in the code block - just make sure you are not still in edit mode. (when you flip to preview mode it runs - for example a widget embed will show up) I made this mistake struggling for about 2 hours the other day and when I figured it out, I wanted to smash my head into the desk for an equal amount of time.
×
×
  • Create New...