Results 1 to 2 of 2

Thread: document.write() not working

  1. #1
    Join Date
    Feb 2007
    Location
    🌎
    Posts
    528
    Thanks
    10
    Thanked 10 Times in 10 Posts
    Blog Entries
    2

    Default document.write() not working

    In this 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:
    HTML Code:
    <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();
    			}
    		</script>
    
    ...
    
    <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?
    ....(o_ Penguins
    .---/(o_- techno_racing
    +(---//\-' in
    .+(_)--(_)' The McMurdo 500

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Try changing:
    Code:
    'javascript:document.write(opendialog(enm[1],"menm1"));'
    to:
    Code:
    'javascript: '+opendialog(enm[1],"menm1"));
    You don't need a document.write() in there. You can just output it as regular javascript content.
    - Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •