使用$ window.open在新选项卡中打开html文本

时间:2016-01-12 04:13:23

标签: javascript angularjs

$window.open('<span>request processed successfully</span>', '_blank');

我希望$window服务在新标签中显示简单文字request processed successfully

但不是它,它将html文本视为位置网址并尝试打开页面http://domain-addr#request processed successfully

如何将html文本参数传递给angular $window服务?

4 个答案:

答案 0 :(得分:1)

您可以在标准JavaScript中执行类似的操作...

function newWindow() {
    // create some html elements
    var para = document.createElement('p');
    var title = document.createElement('title');

    // define some window attributes
    var features = 'width=400, height=400, status=1, menubar=1, location=0, left=100, top=100';
    var winName = 'New_Window';

    // populate the html elements
    para.textContent = 'Some example text.';
    title.textContent = 'New Window Title';

    // define a reference to the new window
    // and open it with defined attributes
    var winRef = window.open('', winName, features);

    // append the html elements to the head
    // and body of the new window
    winRef.document.head.appendChild(title);
    winRef.document.body.appendChild(para);
}

答案 1 :(得分:0)

你可以使用纯粹的javascript,

var w = window.open("www.mydomain.com/test.php", "_blank");
w.document.write('<span>request processed successfully</span>');

答案 2 :(得分:0)

您可以创建一个名为success.htm的简单html文档或类似的&#34;请求已成功处理&#34;并在函数中包含它。 所以$window.open('success.html','_blank', 'size blah blah');

答案 3 :(得分:0)

试试这个:

<强> HTML:

<button id="newWindow">
  Click
</button>

<强> JavaScript的:

//call the function right away
(function() {
  //grab button by id
  var newWindow = document.getElementById("newWindow");
  //add an event listener 
  newWindow.addEventListener("click", function() {
    //create a new p element
    var p = document.createElement('p');
        // change the styles of your paragraph
    // optional
    p.style.color = "red";

    p.style.fontSize = "4em";
    //Insert the text you want
    p.textContent = "request processed successfully";
    //open the window
    var windRed = window.open('', '_blank');
    //append the p element to the new window's body
    windRed.document.body.appendChild(p);
  }, false);
})();