Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2008
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Javascript window manipulation

    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.
    Code:
    <?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...
    Code:
    <?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.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •