top.location.href question

J

Jeff

I'm very new to javascript and need only a small amount in an asp.net
application I'm working on. I apologize if I'm not using the correct
terminology to describe the problem.
I got the code below to work under most conditions to capture the client's
screen resolution and then redirect to another page (but there likely are
better ways to code this). This needs to work under 3 conditions; A) if the
current top.location.href is similar to www.hhh/ B) if the current
top.location.href is similar to www.hhh/?user=xxx and C) if the current
top.location.href is similar to www.hhh/default.apsx

The code below works for situation A and B, but not C. In other words, I
need to redirect to
www.hhh/Prelim/00bPreliminary.aspx
and not to www.hhh/default.aspxPrelim/00bPreliminary.aspx

(while also passing the screen resolution and username if there is one).
Can someone please show me what I'm missing to get rid of the default.aspx
if it is there, or to write this in a better manner?

<script type = "text/javascript" >
<!--
{
res = "res="+screen.width+"x"+screen.height;
y = top.location.pathname ;
a = location.search;
if (a == ""){
a = "?";
}
top.location.href= y+"Prelim/00bPreliminary.aspx"+a+"&"+res;
}
// -->
</script>

Thanks
Jeff
 
R

Randy Webb

Jeff said the following on 12/24/2006 10:57 AM:
I'm very new to javascript and need only a small amount in an asp.net
application I'm working on. I apologize if I'm not using the correct
terminology to describe the problem.
I got the code below to work under most conditions to capture the
client's screen resolution and then redirect to another page (but there
likely are better ways to code this).

Why is the resolution even important? Unless you intend to resize the
window itself I have never understood it's importance unless the
resulting page deals with desktop items or the such.

This needs to work under 3 conditions;
A) if the current top.location.href is similar to www.hhh/
B) if the current top.location.href is similar to www.hhh/?user=xxx and
C) if the current top.location.href is similar to www.hhh/default.apsx

It almost seems pedantic, but you have to define "is similar".
The code below works for situation A and B, but not C. In other words, I
need to redirect to
www.hhh/Prelim/00bPreliminary.aspx
and not to www.hhh/default.aspxPrelim/00bPreliminary.aspx

What would be the initial URL that you need to redirect from? Without
knowing that, a person can only guess as to how to fix the code.
(while also passing the screen resolution and username if there is one).
Can someone please show me what I'm missing to get rid of the
default.aspx if it is there, or to write this in a better manner?

y = top.location.pathname.replace('default.aspx','')

Will remove default.aspx from the location, which is what you are saying
you want to do.
<script type = "text/javascript" >
<!--
{
res = "res="+screen.width+"x"+screen.height;
y = top.location.pathname ;

It may, or may not, be possible in your application but beware that
top.location.pathname will give erroneous results if your page gets
"framed". document.location.pathname is a safer route, then set
top.location.href and it will bust out of any potential framed situations.
 
J

Jeff

Randy Webb said:
Jeff said the following on 12/24/2006 10:57 AM:
Why is the resolution even important? Unless you intend to resize the
window itself I have never understood it's importance unless the resulting
page deals with desktop items or the such.

It is a somewhat specialized application that isn't really intended to pubic
use.
The application really needs everything to show without scroll bars. In the
unlikely event that someone is using a monitor smaller than 800x600 I need
to provide a warning that the application won't work properly.
y = top.location.pathname.replace('default.aspx','')

Will remove default.aspx from the location, which is what you are saying
you want to do.

The code above (with the .replace) works for me.

Thanks.

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top