简体   繁体   English

自定义Javascript在Safari中不起作用?

[英]Custom Javascript doesn't work in Safari?

I am working on a woocommerce site and I have purchased 2 plugins to give the ability to customize the item in my product page. 我正在woocommerce网站上工作,并且已经购买了2个插件,以便可以在我的产品页面中自定义商品。 The plugin demo can be found here : 插件演示可以在这里找到:

In this demo there are 2 plugins, one called Multistep Product Configurator (MSPC) which is the tabs at the top of the page and a second one called Fancy Product Designer (FPD) which is the product display panel underneath it. 在此演示中,有2个插件,一个名为Multistep Product Configurator(MSPC),它是页面顶部的标签;另一个是Fancy Product Designer(FPD),它是其下面的产品显示面板。

I wanted to use these two plugins to display them one next to each other in order to avoid scrolling down the page to see the changes made with MSPC plugin. 我想使用这两个插件将它们彼此相邻显示,以避免向下滚动页面以查看使用MSPC插件所做的更改。

So I have been trying to customise the css code for hours with no success. 因此,我一直在尝试自定义CSS代码达数小时之久,但没有成功。 You can see my page here : I ended up using a custom javascript code in my theme's custom js section which basically repositions the wrapper a few seconds after the page loads. 您可以在这里看到我的页面:我最终在主题的自定义js部分中使用了自定义javascript代码,该代码基本上在页面加载后几秒钟重新定位了包装器。

My issue is that with the js code I achieved what I wanted in all browsers except safari! 我的问题是,通过js代码,我在除野生动物园之外的所有浏览器中都实现了我想要的功能!

Here is the code I used: 这是我使用的代码:

document.onreadystatechange = function(){
 if(document.readyState === 'complete'){
     setTimeout(function () {
         var x = document.getElementsByClassName("mspc-wrapper");
         x[0].style.float = "none";
     }, 3000);
 }

} }

Any idea why it doesn't work in Safari browser? 知道为什么它在Safari浏览器中不起作用吗? Feel free to try fixing this with CSS but I am pretty sure it doesn't work... Any feedback much appreciated. 随时尝试使用CSS修复此问题,但我敢肯定它不起作用...非常感谢任何反馈。

It seems to me that your code for changing the styles is wrong: 在我看来,您更改样式的代码是错误的:

 x[0].style.styleFloat //returns undefined

You'll be wanting to use 您将要使用

x[0].style.float = 'none';

If this doesn't work make sure the js is even running :) 如果这不起作用,请确保js甚至正在运行:)

Safari doesn't seem to support the state 'complete'. Safari似乎不支持“完成”状态。 Try using 'loaded' instead (if it doesn't matter whether the document has been fully loaded or just loaded) since it seems to be supported by all browsers. 请尝试使用“已加载”(如果文档已完全加载还是刚刚加载都没关系),因为似乎所有浏览器都支持它。
Reference 参考

Just to make sure, try debugging it or throwing in a console.log to see if the if-statement ever returns true. 为确保确定,请尝试对其进行调试或放入console.log中,以查看if语句是否返回true。

Ok guys, 好了朋友们,

Thanks a lot for taking a time to respond to this. 非常感谢您抽出宝贵的时间对此做出回应。 What I had to do was to add a hook inside the content-single-product.php and then I could fix it with the CSS code. 我要做的是在content-single-product.php中添加一个钩子,然后可以使用CSS代码对其进行修复。

I didn't need to add the javascript in the end. 我不需要最后添加javascript。

Thanks for replying though! 感谢您的回复!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM