2012-03-07 102 views
0

图像按钮不能正常工作..任何建议?如何将图像按钮添加到使用html中的链接javascript

上我工作当前的代码是: -

var generator = window.open(); 
generator.document.write('<html><head><title>Pop uP</title>'); 
generator.document.write('<p style="color:#C52B27;">'); 
generator.document.write(message); 
generator.document.write('</p>'); 
generator.document.write('</head><body>'); 

generator.document.write('<a href="javascript:self.close()"><img src="/img/save_orange.gif" border=0"><\/a>'); 
generator.document.write('</body></html>'); 
generator.document.close(); 

回答

1

绑定一个js代码片段的图像

<img src="/img/save_orange.gif" border="0" onclick="self.close()"> 

的onclick事件根据这一docself.close()只有工作,如果文档通过window.open()方法打开。 因此,在这种情况下,您可能需要使用 windows.close()

+0

'javascript:'在属性中不是必需的,有些人甚至认为它永远不应该在那里。 – MMM 2012-03-07 14:08:11

+0

@MMM,已确认 – Starx 2012-03-07 14:10:55

+0

@MMM在同一页面中使用多种脚本语言时,该属性中的伪协议是有用的。 – Teemu 2012-03-07 14:15:53

相关问题