?
Solved

Replacing Pound Sign in Window.Location

Posted on 2005-03-30
6
Medium Priority
?
661 Views
Last Modified: 2011-10-03
Simple example of my issue:

on page1.htm, I have a link:

<a href="page2.htm?do=listen#man">click</a>

what i am trying to do on page2.htm is to retrieve the window location url, assign it to a string, and then replace any pound signs in the string with double pound signs in the string.

this is what i've tried on page2.htm:

<script>

var newLocation = '';

newLocation = window.location;
alert(newLocation); // looks like the url is in the newLocation variable

newLocation = newLocation.replace(/\#/g,"");

alert(newLocation);

</script>

Any help would be welcome.
0
Comment
Question by:DanielSKim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 32

Accepted Solution

by:
Batalf earned 2000 total points
ID: 13664904
Try

<script>

var newLocation = '';

newLocation = window.location.href;


newLocation = newLocation.replace(/\#/g,"##");

alert(newLocation);

</script>
0
 
LVL 15

Author Comment

by:DanielSKim
ID: 13664975
%?@!. realized i should have been referencing the property.

thank you!
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13665005
Yes, you have to refer to the href property. In your old code, you tried to replace the location object, which as you realized doesn't work:-)

Batalf
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 63

Expert Comment

by:Zvonko
ID: 13665011
By the way, your so called pound char is the hash character and is used to jump on page to the named anchor name following the hash char.
The named anchor name is provided by the window.location.hash property.

0
 
LVL 15

Author Comment

by:DanielSKim
ID: 13665097
well, that's the issue. i'm receiving a url variable that has a pound sign in it, and the server side script is not seeing the entire variable, as it interprets anything after the pound sign. i want to replace the pound sign with something else, so that the entire variable is passed.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 13665163
the sender of the variable containing the hash char has to urlencode() or to escape() the value before passing it to the url.
In JavaScript you need only then to unescape() the window.location.search to get the passed parameters.

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question