Skip to content

JavaScript function return value in new tab | Example Code

  • by

Create an object of window.open() and then pass the function into document.write() method to pass JavaScript function value into a new tab.

object.document.write(function);

Open New Tab with Results from JavaScript function examples

HTML example codes:-

Add 2 numbers and pass to result into another tab

<html>
<body>
	<script>

		function msg(a, b){
			return a+b;
		}
		
		var winPrint = window.open('', '', width=800,height=600,toolbar=0);

		winPrint.document.write( msg(1,2));	
	</script>

</body>
</html>
Add 2 number and pass to result into another tab JavaScript

Show String message into another tab using JS function

<html>
<body>
	<script>

		function msg(mark){
			if (mark>40){
				return "Hello Wrold"
			}
		}

		var winPrint = window.open('', '', width=800,height=600,toolbar=0);

		winPrint.document.write(msg(200));	
	</script>

</body>
</html>

Output:

JavaScript function return value in new tab

Do comment if you have any doubts and suggestions on this JS function topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *