簡體   English   中英

創建臨時頁面

[英]Create Temporary Page

有人能指出我正確的方向嗎

我需要一個代碼來動態創建一個臨時 Web 彈出頁面,我將使用 VB 在 ASP.NET 中聲明 HTML 內容

這個 function 的原因是我正在嘗試制作申請表打印機,我需要使用

<script>window.print();</script>

您可以將整個 HTML 生成為字符串,然后使用如下:

window.open("data:text/html;charset=utf-8,<head></head><body><h3>Test Document</h3></body><script>window.print();</script>");

基本上,

window.open("data:text/html;charset=utf-8," + YOUR_HTML + "<script>window.print();</script>");

將以下腳本復制粘貼到瀏覽器中進行測試:

data:text/html;charset=utf-8,<head></head><body><h3>Test Document</h3></body><script>window.print();</script>

== 更新 ==
Aspx.vb 代碼

Dim htmlText As String = "<head></head><bod‌​y><h3>Test Document</h3></body>".Normalize()
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "tempWindow", "<script>openTempWindow('" + htmlText + "')</script>", False)

Aspx 代碼

<script type="text/javascript">
    function openTempWindow(content) {
        var win = window.open("");
        win.document.write(content);
    }
</script>

您可以通過操縱響應來實現這一點。 這是動態創建 HTML 文檔的一種方法。 例如:

HttpContext.Current.Response.Write("<html>
<body>
    <h1>Something to print</h1>
</body>
<script>window.print();</script>
</html>")

為了使它成為一個彈出窗口,在您的基本頁面中,您可以在單擊按鈕之后實現window.open()函數。 例如:

window.open("../pageReturningDynamicHTML.aspx?someParam=someValue")

在提供的鏈接中,您可以找到更多示例,說明如何打開帶有大小等設置的彈出窗口。

打開臨時網頁js代碼示例<\/a>

var tempPage = "<html>

<body><a href='https://google.com.vn'>GOOGLE</a></body>

</html>";
var w = window.open('');
w.document.write(tempPage);

暫無
暫無

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

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