admin管理员组文章数量:1026989
I have opened a new window, and now I have a button in this new window. Under this button there is a JavaScript function which should submit the form and insert some content into a <p>
. This "to-add" content also has a html element (close button).
This inserting job is not working. Here is what I tried:
myWindow.document.write("<scrip" + "t>function closeme(){ document.getElementById('danke').innerHTML='thanks <input type=\'button\' onclick=\'window.close()\'/>'; } </sc" + "ript>");
Can someone please help me out?
I have opened a new window, and now I have a button in this new window. Under this button there is a JavaScript function which should submit the form and insert some content into a <p>
. This "to-add" content also has a html element (close button).
This inserting job is not working. Here is what I tried:
myWindow.document.write("<scrip" + "t>function closeme(){ document.getElementById('danke').innerHTML='thanks <input type=\'button\' onclick=\'window.close()\'/>'; } </sc" + "ript>");
Can someone please help me out?
Share Improve this question edited Jan 17, 2013 at 15:39 gen_Eric 227k42 gold badges303 silver badges342 bronze badges asked Jan 17, 2013 at 14:05 doniyordoniyor 38k61 gold badges181 silver badges270 bronze badges 3-
2
First of all, don't use
document.write
- create a script element viacreateElement
instead. This will alleviate your quotes inside of quotes inside of quotes nightmare. Second of all, nothing ever calls yourcloseme
function? – jbabey Commented Jan 17, 2013 at 14:13 -
@jbabey, no, my function
closeme
is being called, i just didnot post it here, because i am sure it is being called. but generally,createElement
is better way? - :))) you made me laugh! – doniyor Commented Jan 17, 2013 at 14:15 - hunlock./blogs/Howto_Dynamically_Insert_Javascript_And_CSS – jbabey Commented Jan 17, 2013 at 14:18
2 Answers
Reset to default 1As said in the ments there are better ways to insert scripts, but in the interests of answering the question, you have to escape the escape characters as well so that they will be present in the output.
myWindow.document.write("<scrip" + "t>function closeme(){ " +
"document.getElementById('danke').innerHTML='thanks <input type=\\\'button\\\' " +
"onclick=\\\'window.close()\\\'/>'; } </sc" + "ript>");
(line breaks added for readability)
I agree there are better ways of doing this, but regarding your specific question. There are escaping issues:
myWindow.document.write("<scrip" + "t>function closeme(){ document.getElementById('danke').innerHTML='thanks <input type=\"button\" onclick=\"window.close()\" />'; } </sc" + "ript>");
I'd honestly add text/javascript
for consistency.
I have opened a new window, and now I have a button in this new window. Under this button there is a JavaScript function which should submit the form and insert some content into a <p>
. This "to-add" content also has a html element (close button).
This inserting job is not working. Here is what I tried:
myWindow.document.write("<scrip" + "t>function closeme(){ document.getElementById('danke').innerHTML='thanks <input type=\'button\' onclick=\'window.close()\'/>'; } </sc" + "ript>");
Can someone please help me out?
I have opened a new window, and now I have a button in this new window. Under this button there is a JavaScript function which should submit the form and insert some content into a <p>
. This "to-add" content also has a html element (close button).
This inserting job is not working. Here is what I tried:
myWindow.document.write("<scrip" + "t>function closeme(){ document.getElementById('danke').innerHTML='thanks <input type=\'button\' onclick=\'window.close()\'/>'; } </sc" + "ript>");
Can someone please help me out?
Share Improve this question edited Jan 17, 2013 at 15:39 gen_Eric 227k42 gold badges303 silver badges342 bronze badges asked Jan 17, 2013 at 14:05 doniyordoniyor 38k61 gold badges181 silver badges270 bronze badges 3-
2
First of all, don't use
document.write
- create a script element viacreateElement
instead. This will alleviate your quotes inside of quotes inside of quotes nightmare. Second of all, nothing ever calls yourcloseme
function? – jbabey Commented Jan 17, 2013 at 14:13 -
@jbabey, no, my function
closeme
is being called, i just didnot post it here, because i am sure it is being called. but generally,createElement
is better way? - :))) you made me laugh! – doniyor Commented Jan 17, 2013 at 14:15 - hunlock./blogs/Howto_Dynamically_Insert_Javascript_And_CSS – jbabey Commented Jan 17, 2013 at 14:18
2 Answers
Reset to default 1As said in the ments there are better ways to insert scripts, but in the interests of answering the question, you have to escape the escape characters as well so that they will be present in the output.
myWindow.document.write("<scrip" + "t>function closeme(){ " +
"document.getElementById('danke').innerHTML='thanks <input type=\\\'button\\\' " +
"onclick=\\\'window.close()\\\'/>'; } </sc" + "ript>");
(line breaks added for readability)
I agree there are better ways of doing this, but regarding your specific question. There are escaping issues:
myWindow.document.write("<scrip" + "t>function closeme(){ document.getElementById('danke').innerHTML='thanks <input type=\"button\" onclick=\"window.close()\" />'; } </sc" + "ript>");
I'd honestly add text/javascript
for consistency.
本文标签: javascriptwindowdocumentwritewrite html element and moreStack Overflow
版权声明:本文标题:javascript - window.document.write - write html element and more - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745665989a2162180.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论