javascript在chrome和firefox中的不同行为

时间:2017-10-10 13:25:15

标签: javascript greasemonkey tampermonkey

下面是我的Grease monkey script / Tamper monkey,点击按钮(多个按钮),其名称包含'attach'。该脚本工作正常,但Chrome和Firefox有所不同。

在Firefox中,点击从“附加”(包含名称)按钮的顶部到底部顺序发生。 在Chrome中,每次页面加载都会从底部到顶部点击。

  1. 为什么这是不同的行为
  2. 我应该使用'==='代替'=='吗?
  3. 下面是我的greasemonkey / tampermonkey脚本

    void ES3DScene::handlePickerClicked(QPickEvent *pick)
    {
        QPickTriangleEvent *trianglePick = qobject_cast<QPickTriangleEvent*>(pick);
        // I'd like to get the vertex data from vertex1Index's position.
        qDebug() << "Clicked " << trianglePick->vertex1Index();
        QGeometry *geometry = m_mesh->geometry();
        auto attributes = geometry->attributes();
        for (auto i = 0; i < attributes.count(); ++i)
        {
            if (attributes.at(i)->name() == QAttribute::defaultPositionAttributeName())
            {
                QAttribute *attribute = attributes.at(i);
                qDebug() << "Attrib " << attribute;
    
                //This is where I'm stuck. I need to read the vertex attributes for the
                //vertex at trianglePick->vertex1Index();
    
                break;
            }
        }
    }
    

1 个答案:

答案 0 :(得分:0)

尝试在这里和那里修复一些小错误 - 因为一个浏览器可能会自动更正语法错误,而其他浏览器则不会(通常情况下我已经注意到了)

var inputs = document.getElementsByTagName('input');

// Add var to keep scope in the for loop
for (var x = 0; x < inputs.length; x++) {

    // Add var here or else it will be global
    var myname = inputs[x].getAttribute('name');

    if (myname.indexOf('attach') == 0) {

        // Syntax error: remove ' ' after (myname)
        document.getElementsByName(myname)[0].click();
    }
}