Click to See Complete Forum and Search --> : modify code
2 peachy
02-16-2003, 06:25 PM
I am trying to modify my code to make it so user can choose the browser size they want.
original code
<script>
function PopUp()
{
// create vaiable to hold url
var url =(url);
// create vaiable to hold features
var features = 'left=0,top=0,';
features += 'screenX=0,screenY=0,';
features += 'width=500';
features += 'height=500';
// ask for the Url
url = window.prompt("Please enter the Url you want.", "");
//check to see if they typed a Url
if (url==null) //they hit Cancel
{
window.alert ("You must enter a Url!");
PopUp()
}
else if (url=="")
{
//user hit ok, but didn't type a Url
window.alert ("You must enter a Url!");
PopUp()
}
//if user typed a Url and clicked OK
if (window.confirm ("OK, Do you want to Resize window and position to top, left?"))
{
//open a new window with the given Url
window.alert ("OK, Going to the Url,re-positioning and re-sizing")
window.open (url,'',features);
}
else
//user hit cancel
{
window.alert ("Ok, will not resize window !");
//open a new window with the given Url
window.open (url);
}
}
</script>
please email me if you can help
iharper@sonic.net
2 peachy
02-16-2003, 06:53 PM
wondering if I explained my problem well enough
Dan Drillich
02-16-2003, 06:57 PM
It works well. What is missing?
2 peachy
02-16-2003, 07:01 PM
I want to make it so the user can enter the size they want the new page to be...
similar to this code....
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Resize Window</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
//<!--
function resizeWin() {
// get dimensions
width = getDimension('width');
height = getDimension('height');
// resize the window (or not)
if ( (height) && (width) ) {
if( confirm("Resize the window to "+ width+"x"+height+" ?") ) {
alert("Resizing");
window.resizeTo(width,height);
}
else {
resizeWin();
}
}
} // end resizeWin
function getDimension(dim) {
val = '0';
while ( (val < 100) || (val > 800) ) {
val = prompt("Type the "+dim+"\n(values between 100 and 800)","")
}
return val;
} // end getDimension
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" onLoad="resizeWin()">
<a href="javascript:resizeWin();">restart</a>
</body>
</html>
geuis
02-16-2003, 07:01 PM
Change the following line. Unless you type http://www.url.whatever w/ the http://, it will not load the page. Loads fine as long as the http:// is type in first.
url = window.prompt("Please enter the Url you want.", "http://");
Geuis
2 peachy
02-16-2003, 07:40 PM
is there a way I can get a prompt to ask for width and height, and make sure they entered between 100 and 800... then go to the new url with the changes ?
2 peachy
02-16-2003, 08:18 PM
anyone got any ideas on how I can modify the code ?
2 peachy
02-17-2003, 12:15 AM
I see a lot of people look at my problem, but not to many responses, does this mean that it can not be done ?
LAwebTek
02-17-2003, 12:28 AM
sure it can be done, try something more like this:
<script language="JavaScript" type="text/javascript">
/* create variables to hold url, height, and width */
var url, nhigh, nwide;
function PopUp() {
// ask for the Url
url = window.prompt("Please enter the Url you want.", "http://");
/*check to see if they typed a valid Url or clicked cancel */
/*http://aa.us would be 12 characters, so must be at least that long*/
if (url.length<12 || url==null)
{
window.alert("You must enter a valid Url!");
PopUp()
}
//if user typed a valid Url and clicked OK
else if (url.length>11) {
//get width and height
getWidth();
getHeight();
//build the window
var features = 'left=0,top=0,';
features += 'screenX=0,screenY=0,';
features += ',width='+nwide+',height='+nhigh;
alert("Going to the Url, re-positioning and re-sizing.")
window.open(url,'',features);
}
}
function getWidth() {
nwide = window.prompt("Enter the desired Width:\nMinimum 100, Maximum 800", "");
if (nwide==null || nwide<100 || nwide>800) {
alert("Invalid entry, Restarting..")
getWidth()
}
}
function getHeight() {
nhigh = window.prompt("Enter the desired Height:\nMinimum 100, Maximum 600", "");
if (nhigh==null || nhigh<100 || nhigh>600) {
alert("Invalid entry, Restarting..")
getHeight()
}
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" onLoad="PopUp()">
<a href="javascript:PopUp();">restart</a>
LAwebTek
2 peachy
02-17-2003, 12:34 AM
that is perfect, but... can I still have the choice of not resizing the window and just going to the url ?
LAwebTek
02-17-2003, 12:40 AM
you can, but if you want me to add it to the script you'll have to wait till tommorrow morning around 10 am est - its 1:39 am and I need sleep, lol :rolleyes:
2 peachy
02-17-2003, 12:43 AM
That will be great, thankyou soooo very much, and
sleep well.
peachy
LAwebTek
02-17-2003, 08:41 AM
You are quite welcome :)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Resize Window</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript">
/* create variables to hold url, height, and width */
var url, nhigh, nwide;
function PopUp() {
// ask for the Url
url = window.prompt("Please enter the Url you want.", "http://");
/*check to see if they typed a valid Url or clicked cancel */
/*http://aa.us would be 12 characters, so must be at least that long*/
if (url.length<12 || url==null)
{
window.alert("You must enter a valid Url!");
PopUp()
}
//if user typed a valid Url and clicked OK
else if (url.length>11) {
//ask visitor to resize or not
var goTo = confirm('Do you want to Resize the window and position it to top, left?');
if (goTo==true) {
//get width and height
getWidth();
getHeight();
//build the window
var features = 'left=0,top=0,';
features += 'screenX=0,screenY=0,';
features += 'width='+nwide+',height='+nhigh;
alert("Going to the Url, re-positioning and re-sizing.")
window.open(url,'',features);
}
else window.open(url)
}
}
function getWidth() {
nwide = window.prompt("Enter the desired Width:\nMinimum 100, Maximum 800", "");
if (nwide==null || nwide<100 || nwide>800) {
alert("Invalid entry, Restarting..")
getWidth()
}
}
function getHeight() {
nhigh = window.prompt("Enter the desired Height:\nMinimum 100, Maximum 600", "");
if (nhigh==null || nhigh<100 || nhigh>600) {
alert("Invalid entry, Restarting..")
getHeight()
}
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" onLoad="PopUp()">
<a href="javascript:PopUp();">restart</a>
</body>
</html>
2 peachy
02-17-2003, 03:50 PM
Thankyou sooo very much, you are an angel.
Peachy