Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-02-2011, 05:30 AM   PM User | #1
MrJosiahT
New to the CF scene

 
Join Date: Jun 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
MrJosiahT is an unknown quantity at this point
Question Javascript that writes a new page with document.write

I've written the following html,
<html>
<head>
<script type="text/javascript">
function createpage(){
var first = document.getElementById('first').value
var second = document.getElementById('second').value
var third = document.getElementById('third').value
var j = window.open('random');
var new_page = '<html><head><script type="text/javascript">function open_win() { window.open(first) window.open(second) window.open(third) } </script></head><body onLoad = "open_win()"></body></html>';
j.document.write(new_page);
j.document.close();
}
</script>
</head>
<body>
<form action="">
<p>
First Link: <input type="text" id="first" name="first"/>
Second Link: <input type="text" id="second" name="second"/>
Third Link: <input type="text" id="third" name="third"/>
<input type=BUTTON value="Submit" name="mySubmit" onClick="createpage();return false;">
</p>
</form>
</body>
</html>

With the intention to eventually implement it into a website that "mashes" several URLs together into a tinyurl that, upon being opened, creates several tabs of the content the creator wanted in the single URL. Does that make sense?
In order to best do this I figured a page with a random character string (I haven't yet implemented this part, for now 'random' holds the place of the new page/link) would have to be created that would launch all the tabs and then close itself.

Here's what it should do...
1) User enter 3 URLs into three forms:
First Link: <input type="text" id="first" name="first"/>
Second Link: <input type="text" id="second" name="second"/>
Third Link: <input type="text" id="third" name="third"/>

2) User clicks Submit button that calls "createpage()" function that's declared in the <head>er. The first part of this function declares the links that were inputted as variables first, second, and, third.
<script type="text/javascript">
function createpage(){
var first = document.getElementById('first').value
var second = document.getElementById('second').value
var third = document.getElementById('third').value
3) "createpage()" function then declares a new window named 'random' to variable j (I have random.html stored in the same folder as this project. It is empty.)
var j = window.open('random')


4) Next "createpage()" creates a variable that stores a full page's html code that includes a script that launches each link individually with window.open().
var new_page = '<html><head><script type="text/javascript">function open_win() { window.open(first) window.open(second) window.open(third) } </script></head><body onLoad = "open_win()"></body></html>';

5) "createpage()" writes the code (stored in variable 'new_page') to document 'random' with j.document.write(new_page);

6) "createpage()" closes the document.
MrJosiahT is offline   Reply With Quote
Reply

Bookmarks

Tags
document.write, function, javascript, page, script

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:50 PM.


Advertisement
Log in to turn off these ads.