简体   繁体   English

Javascript和CSS onclick Div交换

[英]Javascript and CSS onclick Div Swap

I am new to both Javascript and designing for Facebook. 我对Javascript和为Facebook设计都是新手。 I am using Shortstack to create custom tabs and have created a 3 panel sub-tab application using the service. 我正在使用Shortstack创建自定义选项卡,并使用该服务创建了一个3面板子选项卡应用程序。 In the 3rd panel, I have 19 div's holding information. 在第3面板中,我有19格的持有信息。 By default, I use CSS to hide these DIVs (display:none;) and have a series of links at the top of the panel that change the visibility of each DIV onclick. 默认情况下,我使用CSS隐藏这些DIV(display:none;),并在面板顶部具有一系列链接,这些链接可更改每个DIV onclick的可见性。 Only the active onclick content is visible at any time. 随时仅可见活动的onclick内容。

The tab functions properly in Firefox, Chrome, and even Safari on the Mac, but fails in all browsers on the PC, and fails differently. 该选项卡在Firefox,Chrome甚至Mac上的Safari中均能正常运行,但在PC上的所有浏览器中均会失败,并且失败的方式也不同。 In IE, immediately after the swap happens an error message pops up which mentions the publisher not allowing the action in an iFrame. 在IE中,交换发生后,会立即弹出错误消息,提示发布者不允许在iFrame中执行操作。 In Firefox the tab just goes blank with no error message. 在Firefox中,该选项卡只是空白,没有错误消息。

My script is below. 我的脚本在下面。 As I stated, I am new to coding for Facebook and working with Javascript as I am a designer and not a programmer, but am eager to learn. 正如我所说,我是Facebook编程和Java语言的新手,因为我是设计师而不是程序员,但渴望学习。

Thank you in advance for your thoughts and ideas. 预先感谢您的想法和想法。

    function showhide(layer_ref) {
        var thisDiv;
        // check to see if any DIVs are currently showing
        var divlist = ["div1","div2","div3","div4","div5","div6","div7","div8","div9","div10","div11","div12","div13","div14","div15","div16","div17","div18","div19"];
        // loop through the list of DIVs in "divlist"
        for (x = 0; x < divlist.length; x++) {
            thisDiv = document.getElementById(divlist[x]);
            // if the DIV is showing, hide it
            if (thisDiv.style.display == "block") {
                thisDiv.style.display = "none";
            }
        }
        // show the appropriate DIV
        thisDiv = document.getElementById(layer_ref);
        thisDiv.style.display = "block";
    }

If you try to change the things in iframe that could be a problem if the iframe is loaded from different domain. 如果您尝试更改iframe中的内容,如果iframe是从其他域加载的,则可能会出现问题。 It is basically security rule - you don't want to allow rogue code to change/read/write things on the page other than it's own. 这基本上是安全规则-您不想让流氓代码更改/读取/写入页面上的东西,而不是自己的东西。

To answer your question better we need to know where is changing javascript is located and what it tries to change (are those two things loaded from the same domain or not). 为了更好地回答您的问题,我们需要知道javascript的位置以及更改的内容(这两个内容是否从同一域加载)。

The script itself looks ok to me. 脚本本身对我来说还不错。

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

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