簡體   English   中英

如何打開瀏覽器窗口並傳遞HTML內容?

[英]How to open browser window and pass HTML content?

通過單擊按鈕“ push”,我需要打開新窗口並將其傳遞給HTML內容以顯示它。

這是顯示HTML的視圖:

在此處輸入圖片說明

這是控制器的定義:

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>

這是小提琴

我該如何實施?

非常簡單...添加后

.open()

以下代碼

.document.write("Lorem Ipsum");

這是一個jsfiddle

您可以將內容包含在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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM