Clickable link in popup window using fancybox

When I try to use fancybox to open an iframe and scroll to an anchor tag, it works perfectly in IE but not consistently in other browsers. It stops at a different place than the anchor.

I suspect the issue may be related to JavaScript based on information I found here: . However, I am having trouble fixing my code accordingly.

Here is the link:

<a class="various fancybox.iframe" href="cost_of_hire.php#cupcakeanchor"><img src="images/services/4.jpg" alt="" /></a>

And the anchor:

<a name="cupcakeanchor">CUP CAKE MAKING PARTY<br />£0.00</a>

Any assistance would be greatly appreciated. Thanks

PS.: In IE everything is functioning properly, while in Chrome and Firefox 8 out of 12 links work fine, in Safari 6 work correctly, and in Opera none of them work as expected.

Answer №1

When using Fancybox, it seems that anchors do not function properly with certain elements like or . You may want to experiment with using a different element instead.

Answer №2

If you're looking to create a clickable link that opens an iframe with an anchor, you won't be able to do it directly but with some javascript magic, it's totally achievable. I personally used this method in my Prestashop website and it worked like a charm.

Here is an example of how the link should look:

<a href="http://mylink.com/blabla/#myanchor" class="iframe-pv">Click here</a>

And here is the code snippet I used to make it work:

$(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 hope this explanation helps you achieve what you need! Good luck :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide on sending JSON object to Angular custom components

I have implemented a custom element in Angular 7 using the CUSTOM_ELEMENTS_SCHEMA. My app.module.ts code is as follows: export class AppModule { constructor(private injector: Injector) {} ngDoBootstrap() { this.registerCustomElements( ...

Achieving the functionality of making only one list item in the navbar bolded upon being clicked using React and Typescript logic

Currently, in my navigation bar, I am attempting to make only the active or clicked list item appear bold when clicked. At the moment, I can successfully achieve this effect; however, when I click on other list items, they also become bolded, while the ori ...

Error: JSON key data not present in rendering

Here is a JSON string I am working with: {"{\"nodeName\":\"abc\"}":[{"url":"abc","status":true},{"url":"abc","status":true}]," {\"nodeName\":\"pqr\"}":[{"url":"abc","status":true},{"url":"abc","status":true}]} ...

"Headers cannot be set once they have been sent to the client... Error handling for unhandled promise rejection

Having trouble with cookies in the header - specifically, encountering an error at line number 30. The error message reads: "Cannot set headers after they are sent to the client." Additionally, there is an UnhandledPromiseRejectionWarning related to a prom ...

Custom positioning of Mui Snackbar in V5

I've been attempting to position a Snackbar in the top right corner with some customization for the top property, but I'm struggling to get it to display correctly. Here's what I've tried: import React from "react"; import { ...

The combination of Fabric.js, Darkroom.js, and devicePixelRatio offset creates a powerful tool

Having reached out on the Darkroom.js GitHub page with little activity, I'm turning to this platform for assistance. Despite being a great plugin overall, I've run into some issues while testing it on a Retina screen. Everything works fine on a ...

Triggering of NVD3 Angular Directive callback occurring prematurely

Lately, I've delved into utilizing NVD3's impressive angular directives for crafting D3 charts. They certainly have a sleek design. However, I'm encountering numerous challenges with callbacks. While callbacks function smoothly when incorpor ...

Tips for capturing the interaction between a jQuery Dialog and its Parent

Within the parent HTML, there is a call that triggers a JavaScript function. <div class="data"> <form:input title="Building" styleClass="content contractorDisable" maxlength="5" size="6" path="fireImpairForm.bldCode" />&nbsp; <a hre ...

Vue.js is displaying an error message stating that the data property is

I am struggling to access my data property within my Vue.js component. It seems like I might be overlooking something obvious. Below is a condensed version of my code. The file StoreFilter.vue serves as a wrapper for the library matfish2/vue-tables-2. &l ...

Is there still a need to preload dynamic images in the background?

Imagine you have HTML code that includes an image with a placeholder: <img class="lazy-load" src="http://via.placeholder.com/150/?text=placeholder" data-src="http://via.placeholder.com/150/?text=real%20image"/> At some stage, you want to implem ...

Ways to eliminate an item in a JSON structure?

Allow me to elaborate. I received a JSON containing numerous objects: data = [{"id":"784","label":"blah","publisher":"me"},{"id":"785","label":"bleh","publisher":"you"},{"id":"786","label":"blih","publisher":"she"}]; For instance, I am looking to elim ...

Getting the x-axis points on Google charts to start at the far left point

I have integrated the Google API for charts into my application and am using multiple charts on the same page. However, I am facing an issue with setting padding for the charts. When I include more data points, the chart area occupies more space in the div ...

The parent component is failing to pass the form values to the child form group in CVA

My Angular application (view source code on Stackblitz) is running Angular 15, and it utilizes reactive forms along with a ControlValueAccessor pattern to construct a parent form containing child form groups. However, I am encountering an issue where the d ...

How to modify browser's back button action in Vue.js

Is there a way to detect the back function in the browser and then redirect to a different page using Vue.js? Here's what I've tried so far. mounted: function () { window.onpopstate = function(event) { this.$router.push({ path: ...

How can I display a pattern using Javascript?

Can you help me create a JavaScript program using a for loop to print a pattern with n number of asterisks and numbers like this: 1 2 3\n 4 5 6 \n 7 8 9 ...

Add Firebase Data to Dropdown

Utilizing Vuetify to build a dropdown has been an interesting challenge for me. While I can successfully select a value and store it in the firebase database, I'm facing difficulties when it comes to repopulating the dropdown after page refresh. Belo ...

How can you include the product price in the cart using the URL on WooCommerce?

After some exploration, I discovered that I can easily add items to my cart using a specific URL: http://yoururl.com/cart/?add-to-cart=ID Although I was able to figure out how to include quantity and attributes in the link, I have not been able to determ ...

Vue 3 list fails to refresh

Using an API, we are retrieving data: <script setup> import { onMounted, inject } from 'vue' let list = []; function initializeData() { axios .post("/some-link/here") .then((response) => { list ...

What steps can be taken to update the cart if all products have been removed?

How can I implement a refresh for my cart page every time the product length is 0 without causing unreachable code? It seems like there must be a simple solution to this problem. switch (action.type){ case "REMOVE_PRODUCT": return ...

What are the best ways to display nicely formatted JSON data in a text area using React JS?

I am new to React JS and encountered an issue with rendering the pretty JSON data inside a textarea. I'm unsure which part of my code is incorrect, but I want my pretty JSON to be displayed within the textarea as shown below. "email":"<a href="/cd ...