View Full Version : document.write() not working

09-29-2011, 09:35 PM
In this (http://thetortoise.tk/synthetic) site, I am trying to create an effect similar to the DHTML Modal Dialog script. I tried using said script, which did not work. I tried writing a heavily-simplified version, which also did not work.

The window is supposed to open when the superscript number under the electric guitar image is clicked.

I eventually concluded that the problem was with the document.write() method; alert() and other JavaScript works fine. I am testing in both Firefox and Chrome.

The script in question:

<script type="text/javascript">
function opendialog(contents,id) {
return '<div id="d_'+id+'" style="position: fixed; width: 100%; height: 90%; left: 0; top: 0; background-color: rgb(218,218,218); align: middle; z-index: 1000; display: inline; vertical-align: middle;">'+contents+'</div><div id="cd_'+id+'" style="position: fixed; width: 100%; height: 10%; left: 0; top: 90%; background-color: rgb(218,218,218); align: left; z-index: 1000; display: inline; vertical-align: bottom;"><a href="javascript:closedialog('+id+');">close</a></div>';
function closedialog(id) {
document.getElementById("d_"+id).style.z-index = -1000;
document.getElementById("d_"+id).style.display = "none";
document.getElementById("d_"+id).id = "oldd_"+id+new Date().getTime();
document.getElementById("cd_"+id).style.z-index = -1000;
document.getElementById("cd_"+id).style.display = "none";
document.getElementById("cd_"+id).id = "oldd_"+id+new Date().getTime();


<sup><a name="tenm1"></a><span id="tenm1"><a class="tenm" href="#enm1" id="tenlm1">[1]</a></span></sup><script type="text/javascript">enm[1] = "&quot;Fender Highway One Stratocaster&quot; copyright 2009 Martin Taylor (Flickr user <a href=\"http://www.flickr.com/photos/martintaylor\">the other Martin Taylor</a>); available from <a href=\"http://www.flickr.com/photos/martintaylor/3725921928/in/photostream/\">Flickr</a> under <a href=\"http://creativecommons.org/licenses/by-sa/2.0/deed.en\">Creative Commons Attribution-ShareAlike 2.0 Generic</a> free license [<a href=\"http://creativecommons.org/licenses/by-sa/2.0/legalcode\">Legal code</a>]";document.getElementById("tenlm1").href = 'javascript:document.write(opendialog(enm[1],"menm1"));';</script>

Any ideas?

09-30-2011, 03:39 AM
Try changing:


'javascript: '+opendialog(enm[1],"menm1"));

You don't need a document.write() in there. You can just output it as regular javascript content.