Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder feras_wilson's Avatar
    Join Date
    Jul 2005
    Location
    Sweden
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question New Window function with a div

    Hi!
    I have an newwindow function (function newwin()) but its don't work why?

    Code:
    <html>
    
    <head>
    <meta http-equiv="Content-Language" content="sv">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <link href="visa.htm">
    <title>fghfghgfhgfhfgh</title>
    <script>
    function wrapSelection(isTag){
      
    		document.getElementById('tpip');
    		workText = document.selection.createRange();
    		if (document.selection.type == 'Text')
    			{workText.pasteHTML("<"+isTag+">"+workText.text+"</"+isTag+">")
    		
    			}
    
    	} 
    function Undo(theField) {
    	var tempval=eval("document."+theField)
    	if (document.all){
    		tempval.focus()
    		document.execCommand("Undo")
    	}
    }
    
    function newWin() {
    	var html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\
    	<html>\
    	<head>\
    	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\
    	<title></title>\
    	</head>\
    	<body>\
    	<p>Tryck på Arkiv och sen Spara som. Här är din text:</p>\
    	'+ document.jj.tpip +'\
    	</body>\
    	</html>\
    	';
    	var win = window.open();
    	win.document.open();
    	win.document.write(html);
    	win.document.close();
    	win.focus();
    }
    
    </script>
    </head>
    
    <body>
    <form name="jj">
    <Div id='tpip' contenteditable style='width:533px;height:362px;border:1px solid black;overflow:auto'>
    fghfghgfhgfhfgh</Div></form>
    <a href="#" name="ll" onclick="wrapSelection('b')">hfg</a>
    <a href="#" name="ll" onclick="wrapSelection('h1')">indexbold</a>
    <select size="1" name="D1" onchange="wrapSelection(this.value)">
    <option value="h1" selected>h1</option>
    <option value="h2">h2</option>
    <option value="h3">h3</option>
    <option value="h4">h4</option>
    <option value="h5">h5</option>
    <option value="h6">h6</option>
    </select>
    <a href="#" onclick="Undo('jj')">undo</a>
    <a href="#" onclick="newWin()">SAVE</a>
    </body>
    
    </html>
    Please Help!

  • #2
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    change this line:
    Code:
    '+ document.jj.tpip +'\
    to this:
    Code:
    '+ document.getElementById("tpip").innerHTML +'\
    You should know that your code is not cross-browser compatible. If you require further help with this, please repost.

    Hope this helps

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper


  •  

    Posting Permissions

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