473,714 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

create a web page with javascript on fly

Hi,

Is that posible to create a web page completely with javascript and open it
without request to server? Please show a simple sample. Thanks in advance!

Jack
Jul 23 '05 #1
16 23297
"datactrl" <qu***@tpg.com. au> wrote in message
news:41******** @dnews.tpgi.com .au...
Hi,

Is that posible to create a web page completely with javascript and open it without request to server? Please show a simple sample. Thanks in advance!

Jack


A Web page is delivered by a Web server....

Of course you can create a file with an .htm (or .html) extension and
double-click on it in Windows Explorer and it will open. No JavaScript is
necessary to do this; for example:

<html>
<head>
<title>test1.ht m</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>

You can create a page using javascript:

<html>
<head>
<title>test2.ht m<title>
<script type="text/javascript">
var htm = "<html>";
htm += "<head>";
htm += "<title>test3.h tm;
htm += "</head>";
htm += "<body>";
htm += "<h1>Hello World</h1>";
htm += "</body>";
htm += "</html>";
document.write( htm);
</script>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>

Does this answer your question? If not please clarify.
Jul 23 '05 #2
"McKirahan" <Ne**@McKirahan .com> wrote in message
news:Con9d.3528 61$Fg5.74302@at tbi_s53...
"datactrl" <qu***@tpg.com. au> wrote in message
news:41******** @dnews.tpgi.com .au...
Hi,

Is that posible to create a web page completely with javascript and open

it
without request to server? Please show a simple sample. Thanks in advance!
Jack


A Web page is delivered by a Web server....

Of course you can create a file with an .htm (or .html) extension and
double-click on it in Windows Explorer and it will open. No JavaScript is
necessary to do this; for example:

<html>
<head>
<title>test1.ht m</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>

You can create a page using javascript:

<html>
<head>
<title>test2.ht m<title>
<script type="text/javascript">
var htm = "<html>";
htm += "<head>";
htm += "<title>test3.h tm;
htm += "</head>";
htm += "<body>";
htm += "<h1>Hello World</h1>";
htm += "</body>";
htm += "</html>";
document.write( htm);
</script>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>

Does this answer your question? If not please clarify.


Of course
htm += "<title>test3.h tm;
should have been
htm += "<title>test3.h tm</title>";
Here's another possibility.

var htm = "<html>";
htm += "<head>";
htm += "<title>test4.h tm</title>";
htm += "</head>";
htm += "<body>";
htm += "<h1>Hello World</h1>";
htm += "</body>";
htm += "</html>";
var oIE = new ActiveXObject(" InternetExplore r.Application") ;
oIE.visible = true;
oIE.navigate("a bout:blank");
oIE.document.op en;
oIE.document.wr ite(htm);
oIE.document.cl ose;
Jul 23 '05 #3
Lee
datactrl said:

Hi,

Is that posible to create a web page completely with javascript and open it
without request to server? Please show a simple sample. Thanks in advance!


Sure it is, but it has to be loaded from someplace, and it's also very
simple to store a complete web page on the local disk. What, exactly,
are you looking for?

Jul 23 '05 #4
Thanks a lot, McKirahan. The last one is what I want. I would like to pop up
a web page which is completely created by the original page with javascript.
How about if I want to use showModelessDia log() to open it, is that
possible? Thanks again !

Jack

"McKirahan" <Ne**@McKirahan .com> wrote in message
news:BAn9d.2091 30$D%.75621@att bi_s51...
"McKirahan" <Ne**@McKirahan .com> wrote in message
news:Con9d.3528 61$Fg5.74302@at tbi_s53...
"datactrl" <qu***@tpg.com. au> wrote in message
news:41******** @dnews.tpgi.com .au...
Hi,

Is that posible to create a web page completely with javascript and
open
it
without request to server? Please show a simple sample. Thanks in advance!
Jack


A Web page is delivered by a Web server....

Of course you can create a file with an .htm (or .html) extension and
double-click on it in Windows Explorer and it will open. No JavaScript

is necessary to do this; for example:

<html>
<head>
<title>test1.ht m</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>

You can create a page using javascript:

<html>
<head>
<title>test2.ht m<title>
<script type="text/javascript">
var htm = "<html>";
htm += "<head>";
htm += "<title>test3.h tm;
htm += "</head>";
htm += "<body>";
htm += "<h1>Hello World</h1>";
htm += "</body>";
htm += "</html>";
document.write( htm);
</script>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>

Does this answer your question? If not please clarify.


Of course
htm += "<title>test3.h tm;
should have been
htm += "<title>test3.h tm</title>";
Here's another possibility.

var htm = "<html>";
htm += "<head>";
htm += "<title>test4.h tm</title>";
htm += "</head>";
htm += "<body>";
htm += "<h1>Hello World</h1>";
htm += "</body>";
htm += "</html>";
var oIE = new ActiveXObject(" InternetExplore r.Application") ;
oIE.visible = true;
oIE.navigate("a bout:blank");
oIE.document.op en;
oIE.document.wr ite(htm);
oIE.document.cl ose;

Jul 23 '05 #5
Have a search for a message subject "writing slabs of htm".
It was conclusively shown by Lasse that it is much quicker
to write HTML as elements in array, then use join("") to
concatenate them before writing to the page. The length of
time taken using += verus join() is exponentially longer,
getting seriously long for big pages.

There is an example of how to use it below.

Of course, if your content is only small...

Cheers, Rob.

<html>
<head>
<title>Slabs of HTML</title>
</head>
<body>
<script type="text/javascript">
var a = [];
var i = 0;
a[0] = " <p>here is paragraph " + i + "</p>";
a[++i] = " <p>here is paragraph " + i + "</p>";
a[++i] = " <p>here is paragraph " + i + "</p>";
a[++i] = " <table border='1' cellpadding='5' cellspacing='10 '>";
a[++i] = " <tr>";
a[++i] = " <td>This is a cell</td>";
a[++i] = " <td>another cell</td>";
a[++i] = " </tr>";
a[++i] = " <tr>";
a[++i] = " <td>This is a cell</td>";
a[++i] = " <td>another cell</td>";
a[++i] = " </tr>";
a[++i] = " <tr>";
a[++i] = " <td colspan='2' align='center'> ";
a[++i] = " <form name='fred' action=''>";
a[++i] = " <input type='text' name='aTxt' width='50'>";
a[++i] = " <input type='button' value='click me'"
+ "
onclick=\"alert (this.form.aTxt .value);\"><br> ";
a[++i] = " <input type='reset' value='Reset'>" ;
a[++i] = " </form>";
a[++i] = " </td>";
a[++i] = " </tr>";
a[++i] = "</table>";

var s = a.join("");

document.write( s);

</script>
</body>
</html>
Jul 23 '05 #6
Thank's Rob. My question is that I would like to popup a web page from an
already displayed page. And the popup page would like to be created from the
already displayed page with javascript. I think the way using
document.write( ) will change the content of already displayed page. That is
not the question.

I've tried 'new ActiveXObject(" InternetExplore r.Application") ;' sample
provided by McKirahan. I think that would let me open an another window for
the created page. But I got an "automation error" when I run this sample.
Don't know what it is.

Jack
"RobG" <rg***@iinet.ne t.auau> wrote in message
news:Uy******** *********@news. optus.net.au...
Have a search for a message subject "writing slabs of htm".
It was conclusively shown by Lasse that it is much quicker
to write HTML as elements in array, then use join("") to
concatenate them before writing to the page. The length of
time taken using += verus join() is exponentially longer,
getting seriously long for big pages.

There is an example of how to use it below.

Of course, if your content is only small...

Cheers, Rob.

<html>
<head>
<title>Slabs of HTML</title>
</head>
<body>
<script type="text/javascript">
var a = [];
var i = 0;
a[0] = " <p>here is paragraph " + i + "</p>";
a[++i] = " <p>here is paragraph " + i + "</p>";
a[++i] = " <p>here is paragraph " + i + "</p>";
a[++i] = " <table border='1' cellpadding='5' cellspacing='10 '>";
a[++i] = " <tr>";
a[++i] = " <td>This is a cell</td>";
a[++i] = " <td>another cell</td>";
a[++i] = " </tr>";
a[++i] = " <tr>";
a[++i] = " <td>This is a cell</td>";
a[++i] = " <td>another cell</td>";
a[++i] = " </tr>";
a[++i] = " <tr>";
a[++i] = " <td colspan='2' align='center'> ";
a[++i] = " <form name='fred' action=''>";
a[++i] = " <input type='text' name='aTxt' width='50'>";
a[++i] = " <input type='button' value='click me'"
+ "
onclick=\"alert (this.form.aTxt .value);\"><br> ";
a[++i] = " <input type='reset' value='Reset'>" ;
a[++i] = " </form>";
a[++i] = " </td>";
a[++i] = " </tr>";
a[++i] = "</table>";

var s = a.join("");

document.write( s);

</script>
</body>
</html>

Jul 23 '05 #7
datactrl wrote:
Thank's Rob. My question is that I would like to popup a web page from an
already displayed page. And the popup page would like to be created from the
already displayed page with javascript. I think the way using
document.write( ) will change the content of already displayed page. That is
not the question.
If you want to open a modal dialog from the newly generated page, just include an onLoad evend in
<body> tag:

....
a[0] = "<body onLoad='javascr ipt:showModalDi alog(<your parameters>)'>"
....
a[<last>] = "</body>"

I've tried 'new ActiveXObject(" InternetExplore r.Application") ;' sample
provided by McKirahan. I think that would let me open an another window for
the created page. But I got an "automation error" when I run this sample.
Don't know what it is.

It should be a security issue, if you run this from a web server, which is not on your local
machine. So if you want to have a web server where clients access remotely, you shouldn't use
ActiveXObject - just use document.write.

Jack
"RobG" <rg***@iinet.ne t.auau> wrote in message
news:Uy******** *********@news. optus.net.au...
Have a search for a message subject "writing slabs of htm".
It was conclusively shown by Lasse that it is much quicker
to write HTML as elements in array, then use join("") to
concatenate them before writing to the page. The length of
time taken using += verus join() is exponentially longer,
getting seriously long for big pages.

There is an example of how to use it below.

Of course, if your content is only small...

Cheers, Rob.

<html>
<head>
<title>Slab s of HTML</title>
</head>
<body>
<script type="text/javascript">
var a = [];
var i = 0;
a[0] = " <p>here is paragraph " + i + "</p>";
a[++i] = " <p>here is paragraph " + i + "</p>";
a[++i] = " <p>here is paragraph " + i + "</p>";
a[++i] = " <table border='1' cellpadding='5' cellspacing='10 '>";
a[++i] = " <tr>";
a[++i] = " <td>This is a cell</td>";
a[++i] = " <td>another cell</td>";
a[++i] = " </tr>";
a[++i] = " <tr>";
a[++i] = " <td>This is a cell</td>";
a[++i] = " <td>another cell</td>";
a[++i] = " </tr>";
a[++i] = " <tr>";
a[++i] = " <td colspan='2' align='center'> ";
a[++i] = " <form name='fred' action=''>";
a[++i] = " <input type='text' name='aTxt' width='50'>";
a[++i] = " <input type='button' value='click me'"
+ "
onclick=\"ale rt(this.form.aT xt.value);\"><b r>";
a[++i] = " <input type='reset' value='Reset'>" ;
a[++i] = " </form>";
a[++i] = " </td>";
a[++i] = " </tr>";
a[++i] = "</table>";

var s = a.join("");

document.writ e(s);

</script>
</body>
</html>


Jul 23 '05 #8
datactrl wrote:
Thank's Rob. My question is that I would like to popup a web page from an
already displayed page. And the popup page would like to be created from the
already displayed page with javascript. I think the way using
document.write( ) will change the content of already displayed page. That is
not the question.

[snip]

If you want the content in a new window, then create a new window called
(say) newWindow and write to it:

newWindow = window.open('', 'Window Title','paramet ers....');

...

slabs of HTML

...

newWindow.docum ent.write(s);

Then the HTML appears in newWindow, not the current one.
Cheers, Rob.
Jul 23 '05 #9
Lee
RobG said:

datactrl wrote:
Thank's Rob. My question is that I would like to popup a web page from an
already displayed page. And the popup page would like to be created from the
already displayed page with javascript. I think the way using
document.write( ) will change the content of already displayed page. That is
not the question.

[snip]

If you want the content in a new window, then create a new window called
(say) newWindow and write to it:

newWindow = window.open('', 'Window Title','paramet ers....');

...

slabs of HTML

...

newWindow.docum ent.write(s);

Then the HTML appears in newWindow, not the current one.


Sometimes. But sometimes you get an error because newWindow.docum ent
has no properties, because the O/S hasn't opened the new window fast
enough, so you're trying to write into a window that isn't ready.

globalHTML=s;
window.open("ja vascript:opener .globalHTML");

is more reliable.

Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1583
by: Joe Finsterwald | last post by:
Recently I needed to add a confirm to a LinkButton that called a JavaScript function on success, and did nothing on failure. I found documentation on adding a confirm, but not on how to place a confirm in a conditional. In any case, I've found the answer and I thought I'd share. In VB.NET (in the code behind in VS.NET) Adding just a confirm...
1
1887
by: Axel Dahmen | last post by:
Hi, I can't create local fragment hyperlinks or JavaScript hyperlinks in ASP.NET. It always appends the current path to any value. How can I switch that off? Examples: * NavigateUrl="#highlight"
2
1768
by: Jensen bredal | last post by:
Hello, I have some javascript on my page but i can see that these scripts are not beeing run on post back. The only run the first the page loads. Is there a way to tell the "Page object" tu run all javascript every time i enter the "page_load" routine? Many thanks in advance
1
1576
by: philmaz | last post by:
What I am trying to do is create a form that people can use to enter their email address to sign up for a mailing list. Once they enter their email address, I want the script to open up a txt file that is stored on the server and write the email adress to the bottom of the txt file. Then close and save the file. Is this at all possible to do with client side script on any kind? go to http://www.thetimelineband.com/emailform.html to...
2
1572
by: theseer | last post by:
I need to create an application where I need to obtain variables from one page and pass that to a javascript function on another. Is it possible to pass variables from one page into a JS function on another? If not, how do I simulate another page within the same page? Apologies for the strange phrasing and repetition above. ;)
3
2271
by: GroupReader | last post by:
I posted a similar question earlier and got lots of good feedback, but now I have more information: Problem: I have javascript in a user control that is not "loading" properly. When I try to call the script from my page, I get "object not found". Temporary Workaround: This only happens when I have "debug=true" in my web.config. If I remove debug=true then then script works fine.
0
1155
by: Suresh Sharma | last post by:
i want to know how to create page dynamically like Sulekha.com which show his record per html page through programm. I am working on project such like this and i want to implement like this? when i click 'next' button then it give (page1,page2,..........so on at last paging data showing. At this time page creation depend on data .
5
3675
by: plsHelpMe | last post by:
How to create dynamic javascript arrays using dojo toolkits Hello frens, I am in a big trouble. My objective is: I am having some categories shown by differnent radio buttons, on the click of a particular radio button i making an ajax call using dojo and retirieving the data corresponding to that category. Now i am suppose to create array of that data using the javascript dynamically. Can anyone please help me for the same. For your...
2
6964
by: pankajsingh5k | last post by:
Dear All, Please help me... I had read an article to lazy load a tab in a tabcontainer using an update panel on http://mattberseth.com/blog/2007/07/how_to_lazyload_tabpanels_with.html and i am implementing it in my website....
0
8795
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8701
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9068
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6621
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4462
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4715
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3155
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2103
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.