Solved

Sticky Bar Refer to Parent URL

  • 13 October 2023
  • 4 replies
  • 81 views

Badge

I have a sticky bar with a link in, which I want to point to a section on the parent pages. Ideally I’d just use javascript to overwrite the link in the sticky bar to “domain.com/page#section.” Any attempt to refer to the parent URL with javascript just seems to give domain.com instead of domain.com/page. How can I refer to domain.com/page so that I can append the relevant section?

icon

Best answer by Hristian 18 October 2023, 08:22

View original

4 replies

Userlevel 7
Badge +3

Hey @alexg

In your JS script you have to account for the fact that sticky bars load as iFrames and you need “communicate” between the iframe and the main page. 

It’s not impossible but a bit tricky. 


Best,
Hristian 

Badge

Hey @Hristian,

Can you provide any info around how I account for that fact? Sorry that feels very vague.

 

Thanks,

Alex

Userlevel 7
Badge +3

Hey @alexg

I wasn’t trying to be vague on purpose… just thought that pointing you in the right direction should be enough. 

Like I said in my original answer, since the sticky bars are essentially iframes you can’t communicate directly with the parent page - mostly for security reasons. 

However, there is a solution/workaround if you use  

parent.postMessage( )


You’ll need 2 scripts:

  1. The first on your sticky bar that would “send” the information.
  2. The second on your parent page that would “read” the message from the iframe and adjust the URL accordingly. 


If you’ve done the above and still not getting the result you want, maybe the problem is with your script. Hard to tell by just your original message.



Best,​​​​​​​

Badge

Awesome, thanks Hristian!

Reply