Jump to content

Is it possible to include an anchor link in a link fancybox ?


Superbegood31

Recommended Posts

Hello,

I wish to add an anchor in a link "fancybox".

The structure of this link :

<a class="iframe" href="index.php?id_cms=3&controller=cms&content_only=1">texte</a>

I said that I have placed the code snippet in my footer

<script type="text/javascript">
    $('a.iframe').fancybox({
        'type' : 'iframe',
        'width':700
    });
</script>

On the landing page (id_cms = 3) I placed an anchor and I'd like to open this link is placed on the anchor.

I tried to place the anchor directly in the link above but it does not work ...

Thank you for your lights.

Edited by SWITCHBOARD (see edit history)
Link to comment
Share on other sites

Hi vekia,

 

The class = "iframe" is present.

 

I tried

<a class="iframe" href="index.php?id_cms=3&controller=cms&content_only=1&#licence">text</a>
<a class="iframe" href="index.php?id_cms=3&controller=cms&content_only=1" rel="licence">text</a>
<a class="iframe" href="index.php?id_cms=3&controller=cms&content_only=1#licence">text</a>

but nothing works...

 

Thanks for your help

Link to comment
Share on other sites

    $('a.iframe').fancybox({
        'type' : 'iframe',
        'width':700
    });

try to change this code to:

$(document).ready(function(){
    $('a.iframe').fancybox({
        'type' : 'iframe',
        'width':700
    });
});

and if it is possible - please share url to your website.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...

Hi @Switchboard,

 

I had the same problem but I found a fix to do the trick. If you want to open an iframe with an anchor you can't use directly on the url but it's possible to accomplish by javascript.

 

For example:

 

<a href="{$link->getCMSLink('3')}#myanchor" class="iframe-pv">{l s='My anchored link'}</a>

 

 

It will work with query parameters and rewrited urls and now it's not necessary to add content_only parameter on your link.

 

My code on global.js file:

$(document).ready(function(){

	$(document).on('click', 'a.iframe-pv', function(e){
		e.preventDefault();
		var anchor = '';
		var url = $(this).attr('href');
		var anchorIdx = url.indexOf('#');

		if (anchorIdx > -1) {
			anchor = url.substring(anchorIdx, url.length);
			url = url.substring(0, anchorIdx);
		}

		if(url.indexOf('content_only=') == -1) {
			url += (url.indexOf('?') > -1) ? '&' : '?';
			url += 'content_only=1';
		}

		if (!!$.prototype.fancybox){
			$.fancybox({
				'padding':  20,
				'width':    '70%',
				'height':   '70%',
				'type':     'iframe',
				'href':     url + anchor
			});
		}
	});
});

I've tested on Chrome, FF & IE. I hope it helps  :)

Edited by ericzon (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...