modifying the content of the address bar without triggering apostback

N

nimad

Hello,

I would like to modify the content of the location bar (address bar)
using JavaScript. Suppose I am at
http://localhost/WebTests/TestEvent.aspx
The followig line:
window.location = "aaa";
changes the content of the address bar to:
http://localhost/WebTests/aaa

which is fine except that it then goes ahead and causes a full
postback to the server. How can I change the content of the location
bar without causing a postback?

I can also use
location.hash="aaa";
this does not trigger a postback but changes the content of the
address bar to:
http://localhost/WebTests#aaa

and i want
http://localhost/WebTests/aaa

Thanks!
 
V

VK

Hello,

I would like to modify the content of the location bar (address bar)
using JavaScript. Suppose I am athttp://localhost/WebTests/TestEvent.aspx
The followig line:
window.location = "aaa";
changes the content of the address bar to:http://localhost/WebTests/aaa

which is fine except that it then goes ahead and causes a full
postback to the server. How can I change the content of the location
bar without causing a postback?

I can also use
location.hash="aaa";
this does not trigger a postback but changes the content of the
address bar to:http://localhost/WebTests#aaa

and i wanthttp://localhost/WebTests/aaa

Thanks!

So like user comes to some malicious site but the script shows
http://www.bankofamerica.com in the address bar so the user would have
full confidence to type in his online account info? I am not saying
that you are doing something like this: I am just explaining why no
one browser will allow to do anything like this for obvious security
reasons. Moreover, in IE7 and higher address bar is now enforced for
all script-generated windows. That is another frequent question here:
"how to remove address bar in window.open?" and the same answer: you
cannot do it for the security reasons.
 
N

nimad

So like user comes to some malicious site but the script showshttp://www.bankofamerica.comin the address bar so the user would have
full confidence to type in his online account info? I am not saying
that you are doing something like this: I am just explaining why no
one browser will allow to do anything like this for obvious security
reasons. Moreover, in IE7 and higher address bar is now enforced for
all script-generated windows. That is another frequent question here:
"how to remove address bar in window.open?" and the same answer: you
cannot do it for the security reasons.

Thanks VK,

If I wanted to change the base url it would obviously be a major
security breach and it would make sense for the browsers to not allow
it. What i am trying to do is to change what comes after www.mysite.com
to www.mysite.com/pages/mypage. since a portion of the page remains
the same, I want to refresh the part that changes using an ajax asynch
call and simultaneously alter the url in the address bar so if a user
copies and pates it as a link on their page, it will point to the same
page on my server and linking is enabled. If I use
location.hash="aaa"; I will get www.mysite.com#aaa without a post back
and if I use location.search="xxx"; I will get get www.mysite.com?aaa
without a post back
but if I use location.pathname="xxx"; I will get www.mysite.com/aaa
with a post back.

Now when we do location.pathname="xxx", we are modifying an object
which then triggers a submit event. The preventDefault method is
supposed to cancel an event. So using preventDefault in conjunction
with the stopPropegation method should stop the event from firing. I
have not been able to make it work here. Do you have any thoughts or
has anyone been able to get this to work?
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top