如何打开浏览器窗口并传递HTML内容?

时间:2016-06-13 12:36:13

标签: javascript html angularjs

点击按钮“推”我需要打开新窗口并传递给它HTML内容以显示它。

以下是显示HTML的视图:

enter image description here

这是控制器定义:

var test = angular.module('test', []);

test.controller('testController', ['$compile', '$scope','$window', function($compile, $scope, $window) {
    $scope.openWindow = function() {
        $window.open('to-print', 'width=500,height=400');
    };}]);

这是HTML内容:

<div ng-app="test" id = "content" ng-controller="testController">
<label>Entar Name:</label>
<label>Michael</label>
<br/>
<br/>
<label>Entar Age:</label>
<label>25</label>
<hr/>
    <button ng-click="openWindow()">push!</button>
</div>

我要在打开的窗口中显示的HTML是:

<label>Entar Name:</label>
<label>Michael</label>
<br/>
<br/>
<label>Entar Age:</label>
<label>25</label>

这是fiddle

我该如何实施?

2 个答案:

答案 0 :(得分:1)

这很简单......

之后添加

.open()

以下代码

.document.write("Lorem Ipsum");

这是jsfiddle

答案 1 :(得分:1)

您可以在 documet.write()功能

中加入您的内容
<script>
    function myFunction() {
        var myWindow = window.open("", "","width=600,height=100");
        myWindow.document.write("<label>Entar Name:</label><label>Michael</label><br/><br/><label>Entar Age:</label><label>25</label>");
    }
</script>