setAttribute target _blank无法在新选项卡中打开

时间:2016-02-22 21:45:20

标签: javascript

Map<String, String> header = new HashMap<String, String>();
header.put("OrderIncrementId", "ORD-4426");

Map<String, String> detail_1= new HashMap<String, String>();
details.put("order_item_id", "1229");
details.put("qty", "1");

List<Map<String,String>> details = new ArrayList<Map<String,String>>();
details.add(detail_1);

List<Object> finalList = new ArrayList<Objec>();
finalList.add(header);
finalList.add(details);

<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" soapenc:arrayType="xsd:anyType[2]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
            <multiRef href="#id1"/>
            <multiRef href="#id2"/>
        </multiRef>
        <multiRef id="id2" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" soapenc:arrayType="xsd:anyType[1]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
            <multiRef href="#id3"/>
        </multiRef>
        <multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:Map" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
            <item>
                <key xsi:type="soapenc:string">orderIncrementId</key>
                <value xsi:type="soapenc:string">ORD-4426</value>
            </item>
        </multiRef>
        <multiRef id="id3" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:Map" xmlns:ns3="http://xml.apache.org/xml-soap" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
            <item>
                <key xsi:type="soapenc:string">order_item_id</key>
                <value xsi:type="soapenc:string">1229</value>
            </item>
            <item>
                <key xsi:type="soapenc:string">qty</key>
                <value xsi:type="soapenc:string">1</value>
            </item>
        </multiRef>

以上代码对我不起作用。如果点击事件发生在var a = document.createElement('a'); a.setAttribute('target','_blank'); a.click();

setAttribute不起作用

2 个答案:

答案 0 :(得分:4)

没有href属性的锚点元素不能链接到任何地方,因此它们不是链接,因此点击一个

当我添加setAttribute("href", "something")时,它在我的测试中触发了一个新窗口。

答案 1 :(得分:2)

如果您还设置了href属性

a.setAttribute('href','https://google.com')

然后,当您调用a.click()时,您最有可能看到的内容(在Chrome和Canary中)是浏览器将阻止此弹出窗口。这是因为这几乎是教科书烦人的弹出窗口,并且由于点击不是首先通过用户的点击启动,因此它被视为垃圾邮件。

如果你需要这样做,它通常会在你触发内部&#34;点击&#34;来自某个类型的用户启动(onclick)事件处理程序。