473,320 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

top.location.href question



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
--
Posted via a free Usenet account from http://www.teranews.com

Dec 24 '06 #1
2 8710
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.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 24 '06 #2

"Randy Webb" <Hi************@aol.comwrote in message
news:rP********************@telcove.net...
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
--
Posted via a free Usenet account from http://www.teranews.com

Dec 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Andrea | last post by:
Hi everyone, I am in the process of learning javascript and have a question on location.href. Does javascript always require the <script language = "javascript"> (or script...
3
by: Robert Mark Bram | last post by:
Hi All! I have a piece of JavaScript that attempts to find the location.href property of another window. For example: contentWindow = window.open('', 'someWindowName'); var otherUrl =...
9
by: Kreso | last post by:
i'm passing the asp parameters using the url current page is files.asp and I'm using window.location.href=files.asp?action=deletefile to pass the action to the serverside My code never got...
3
by: saiho.yuen | last post by:
Hi, Is anyone know what is the difference between Location.href and Window.location.href Thanks you very much:) Saiho
8
by: Phil Powell | last post by:
if (document.location.href.indexOf('?') >= 0) document.location.href = document.location.href.substring(0, document.location.href.indexOf('?')); if (document.location.href.indexOf('#') >= 0) {...
2
by: yogesh.bhardwaj | last post by:
Hello all I am trying to modify the link URL when a user clicks on the link. Following is the code: <a onClick="document.location.href=modifyURL(this.href);" href="SOME_DYNAMIC_URL"...
3
by: Christian Hubinger | last post by:
Hi! I'm working on a page that uses javascript very much. My problem is now that i cannot redirect to another page in IE with window.location =<URL>; This command gets executed (proofed with...
6
by: G*rd*n | last post by:
I have been using the HTTP "Location" reponse header to direct a symbolic request to a CGI program to an actual URL/file. For example, let us suppose the CGI program's table indicates xyz ->...
4
by: ChrisC | last post by:
I have a nice simple page - navigation frame on the left, main panel on the right - <frameset cols = "20%, 80%"> <frame src="LeftPanel.aspx" id="leftFrame" name="leftFrame" width="20%"...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.