Luca Luca - 2 months ago 17
HTML Question

Custom popup not opening on Safari

I'm trying to open a custom popup in my website. However, it doesn't work on Safari.

This is how I call it:

<img id="product-1" class="product-box" src="images/image.jpg" onclick="openProduct(1)">


openProduct() does this:

function openProduct(id){
activeID=id;
openPopup();
fillPopupContent(id);
}
function openPopup(){
document.getElementById("popup").style="opacity:1;z-index:1000";
}


It works perfectly good on any other browser, but not in Safari.

Adding an
alert();
in the function shows that it calls the function with success. However, I can't see the popup.

If any of you have any suggestion...

Answer

The style property should return a CSSStyleDeclaration object that contains key/values for the styles.

Why it works in other browsers seems strange, as the syntax you're using is wrong, it should be

function openPopup(){
    var popup = document.getElementById("popup");

    popup.style.opacity = "1";
    popup.style.zIndex = "1000";
}
Comments