...

View Full Version : Javascript window manipulation



snotrocket
05-03-2008, 01:46 AM
Ok so I'm totally lost on this project that I've been working on.

I'll write out the guidelines of what I have to do.

Create a page.html which has 4 buttons and a link ?id=abc&pw=123&address=NY

- First button opens a new window and brings focus to it
- Link opens page2.html and passes a search string "?id=abc&pw=123&address=NY"
- Second button retrieves the search string, processes it, and displays each name/value pair on one line.
- Third button displays Google.com in said browser.
- Fourth button closes window.

So basically, I have a page with 4 buttons and one link, which open a new window, display processed information in it, open google in the window, and close the window. So, the link hub is page1, and everything else has to happen in page2.

Here is what I have for page 1. Please note that I have cheated by opening a new window in each function. I should just have to reference the myWin I created earlier, but that doesn't seem to work.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Page1</title>
</head>

<body>
<script type="text/javascript">

function winOne(){
var myWin = window.open("","myWin");
}

function process(){
window.open("page2.html?id=abc&pw=123&address=NY.html","myWin");
var y = myWin.location.search;
x = y.substring(1,y.length);
yArray = x.split("&");
myWin.document.writeln("First pair of name and value is " + yArray[0] + "<br />");
myWin.document.writeln("Second pair of name and value is " + yArray[1] + "<br />");
myWin.document.writeln("Third pair of name and value is " + yArray[2]);
}

function google(){
window.open("http://www.google.com", "myWin");
}

function closeWin(){
window.open("","myWin");
myWin.close();
}

</script>

<form>
<input type="button" value="click here to open a window" onclick="winOne()"/><br/>
<a href="page2.html?id=abc&pw=123&address=NY" target="myWin" onclick="myWin.focus()">Click here to display page2.html and send a search string</a><br/>
<input type="button" value="Click here to process the search string" onclick="process()"/><br/>
<input type="button" value="Click here to display Google.com" onclick="google()"/><br/>
<input type="button" value="Click here to close the window" onclick="closeWin()"/><br/>
</form>

</body>
</html>

And for page 2...

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Page2</title>
</head>

<body>
</body>
</html>

The button to process the information and display, and the button to close the window don't work at all.

Kor
05-03-2008, 08:33 AM
http://www.codingforums.com/showpost.php?p=684369&postcount=2



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum