Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6831965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:48:02+00:00 2026-05-26T22:48:02+00:00

I’m using the ColorBox jQuery plugin to create modal lightboxes for different purposes around

  • 0

I’m using the ColorBox jQuery plugin to create modal lightboxes for different purposes around my site. In some cases, we’d like the ajax modal box to create a new history state in the browser so that if I user clicks the Back button, it will close the modal box and bring them back to the underlying view.

Firstly, is behavior like this possible with ColorBox? Second, I’ve looked into window.onhashchange and also this hashchange plugin, but I’m really struggling to put something working together with the ColorBox plugin. I’m hoping someone has attempted or successfully accomplished something similar who may have some insight on how this may be accomplished.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:48:03+00:00Added an answer on May 26, 2026 at 10:48 pm

    Yeah, that can be done. Here I am assuming you are going to use inline content (hidden) for your modals. Links will open your colorbox modals, but rather than attaching the colorbox to the link in the normal way, you just use normal links with a query parameter defining which modal to open: ?cb=modal1. Then in your docReady you just look for colorbox parameters in the query string and open the appropriate colorbox. This way, it doesn’t matter where your link is, and there’s no need to declare the links as a colorbox link. This example uses the getParameterByName function in this answer, but of course you can use any strategy you like to pull the query params.

    $(document).ready(function() {
        var modal = getParameterByName("cb");
    
        if(modal != "") {
            $.colorbox({
                href: "#" + modal,
                inline: true
            });
        }
    });
    

    Then any link to a modal would be:

    <a href="yourpage?cb=modal1">Open modal 1</a>
    

    Check out the full code for that one at this jsfiddle.

    Update: Back button closes colorbox

    After reading your comments, I understand better what you want to achieve. So if you only need to close the colorbox when user clicks the back button, instead of query strings you could use url hashes in your links:

    <a href="#colorbox-modal1">Open colorbox</a>
    

    In order to watch for changes in the location hash, you could use this jQuery onhashchange plugin, or something similar. And then in your docReady:

    $(document).ready(function() {
        $(window).hashchange(function(){
                //gets the colorbox content id from the url hash
            var getCb = function() { return location.hash.match(/(#colorbox-.*)/) && RegExp.$1 },
                cb = getCb();
    
            if(cb) {
                $.colorbox({
                    href: cb, 
                    inline: true,
                    //if closing with ESC key or overlay click, we
                    //need to go back so that hashchange is fired
                    //if the same colorbox is opened again
                    onClosed: function() {
                        if(getCb()) {
                            history.go(-1);
                        }
                    }
                });
            } else {
                $.colorbox.close();
            }
        })
    });
    

    Here’s the fiddle for that, but with a disclaimer: IE8 and IE9 have problems with this code while it’s inside a fiddle. Seems ok when I take it out, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.