开发者

Lightbox that can open automatically depending on url path

There are a million lightbox type modal overlay scripts out there.. but I am looking for one that has the ability to be automatically triggered, depending on the path that leads there. So a property would have to live in the url string that triggered it. Has anyone seen or implemented any such thing? I know colorbox has the ability to automat开发者_高级运维ically open the modal when you land on the page, but I do not know how I could make that functionality dependant on the path that one arrives there. Any ideas?


You could implement some JavaScript that looks at the referring page and opens the light box accordingly, therefore you shouldn't be limited to a particular implementation. You can tie in to the document ready event to open it.

There is an example of how to access the referrer on the W3Schools website linked below.

http://www.w3schools.com/jsref/prop_doc_referrer.asp


You can do this with Colorbox by varying the settings in your initialisation.

Assuming that you do this to start Colorbox:

$('div.gallery a').colorbox({
    onClosed: function() { alert('Colorbox closed');},
    current: 'Image {current} of {total}'
});

You could do something like this instead:

var colorBoxSettings = {
    onClosed: function() { alert('Colorbox closed');},
    current: 'Image {current} of {total}',
    open: false
};

if (your_logic) {
    colorBoxSettings.open = true;
}

$('div.gallery a').colorbox(colorBoxSettings);


I suggest that there is no need for auto triggering. You can do it this way -

First check the whether the url consists of the appropriate value you want or not.

It can be done by server side language (like PHP ) or through javascript.

If done server side pass say a hidden field as below -

<input type="hidden" name="exists" value="true" />

If done using jquery save value as -

var value = "value from javascript if proper url exists";

If done through server side then -

var value = $('input[name="exists"]').val();

Then you can trigger manual cilck (if url value is as per your expectation) to anchor which consists of overlay link -

$('#id of anchor').trigger('click');

If you want auto triggering overlay though then you can try this -

http://flowplayer.org/tools/demos/overlay/trigger.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜