简体   繁体   中英

Create Temporary Page

can someone point me to the right direction

I need a code to dynamically create a temporary Web Pop-up Page which I'll declare the HTML Content in ASP.NET Using VB

reason for this function is that I am trying to make Application Form printer and I need to print the current page with the

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

You could generate the entire HTML as string and then use as below:

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

Basically,

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

Copy paste the below script in a browser to test:

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

== Updates ==
Aspx.vb Code

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 Code

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

You can achieve that by manipulating the response . This is one way to dinamically create an HTML document. For example:

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

In order to make it a popup window, in your base page you can implement window.open() function after, lets say, a button click. For example:

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

In the provided link you can find more examples on how to open a window as popup with settings as sizes and more.

Open temporary webpage js Code Example<\/a>

var tempPage = "<html>

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM