473,385 Members | 1,317 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,385 software developers and data experts.

Capturing current page's URI?

I am wondering if the following can be accomplished with javascript
(and if so, if you think javascript is an appropriate solution). I'm
afraid my javascript skills lack. I need to build a hyperlink that
includes the current web page URI. When clicked, the current page is
then processed by a program. For example, it would look something
like this:

<a href="http://some.program.com/index.php?current-web-page-URI">text
etc.</a>

where "current-web-page" would be the full URI,
http://whatever.com/stuff/index.html

Resulting in:

<a
href="http://some.program.com/index.php?http://whatever.com/stuff/index.html">text
etc.</a>

Thus I need a way to grab the current web page's URI for the
hyperlink. This hyperlink would be on numerous different pages and is
why the page's URI will differ.

They're not PHP generated pages, though that thought is a possibility,
else I would use something like PHP's $_SERVER['REQUEST_URI']

While a server side solution might be preferable to a client side
solution, people using the site don't have javascript turned off
because of other javascripts at the site.

Therein is my situation. If anyone has comment or suggestions on how
to script this, I would be much obliged.

TIA
Oct 13 '05 #1
4 2099
Sandy Bremmer said the following on 10/12/2005 11:07 PM:
I am wondering if the following can be accomplished with javascript
(and if so, if you think javascript is an appropriate solution). I'm
afraid my javascript skills lack. I need to build a hyperlink that
includes the current web page URI. When clicked, the current page is
then processed by a program. For example, it would look something
like this:

<a href="http://some.program.com/index.php?current-web-page-URI">text
etc.</a>

where "current-web-page" would be the full URI,
http://whatever.com/stuff/index.html

Resulting in:

<a
href="http://some.program.com/index.php?http://whatever.com/stuff/index.html">text
etc.</a>


Have PHP generate the links and include the current URL.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 13 '05 #2
"Sandy Bremmer" <no_email_please@prefer_the_newsgroups.com> wrote in message
news:kk********************************@4ax.com...
I am wondering if the following can be accomplished with javascript
(and if so, if you think javascript is an appropriate solution). I'm
afraid my javascript skills lack. I need to build a hyperlink that
includes the current web page URI. When clicked, the current page is
then processed by a program. For example, it would look something
like this:

<a href="http://some.program.com/index.php?current-web-page-URI">text
etc.</a>

where "current-web-page" would be the full URI,
http://whatever.com/stuff/index.html

Resulting in:

<a
href="http://some.program.com/index.php?http://whatever.com/stuff/index.html
">text etc.</a>

Thus I need a way to grab the current web page's URI for the
hyperlink. This hyperlink would be on numerous different pages and is
why the page's URI will differ.

They're not PHP generated pages, though that thought is a possibility,
else I would use something like PHP's $_SERVER['REQUEST_URI']

While a server side solution might be preferable to a client side
solution, people using the site don't have javascript turned off
because of other javascripts at the site.

Therein is my situation. If anyone has comment or suggestions on how
to script this, I would be much obliged.

TIA


Will this help? Watch for word-wrap.

<script type="text/javascript">
document.write("<a href='http://some.program.com/index.php?" + location.href
+ "'>link</a>");
</script>
Oct 13 '05 #3
On Wed, 12 Oct 2005 23:20:46 -0500, "McKirahan" <Ne**@McKirahan.com>
wrote:
"Sandy Bremmer" <no_email_please@prefer_the_newsgroups.com> wrote in message
news:kk********************************@4ax.com.. .
I am wondering if the following can be accomplished with javascript
(and if so, if you think javascript is an appropriate solution). I'm
afraid my javascript skills lack. I need to build a hyperlink that
includes the current web page URI. When clicked, the current page is
then processed by a program. For example, it would look something
like this:

<a href="http://some.program.com/index.php?current-web-page-URI">text
etc.</a>

where "current-web-page" would be the full URI,
http://whatever.com/stuff/index.html

Resulting in:

<a

href="http://some.program.com/index.php?http://whatever.com/stuff/index.html
">text
etc.</a>

Thus I need a way to grab the current web page's URI for the
hyperlink. This hyperlink would be on numerous different pages and is
why the page's URI will differ.

They're not PHP generated pages, though that thought is a possibility,
else I would use something like PHP's $_SERVER['REQUEST_URI']

While a server side solution might be preferable to a client side
solution, people using the site don't have javascript turned off
because of other javascripts at the site.

Therein is my situation. If anyone has comment or suggestions on how
to script this, I would be much obliged.

TIA


Will this help? Watch for word-wrap.

<script type="text/javascript">
document.write("<a href='http://some.program.com/index.php?" + location.href
+ "'>link</a>");
</script>


Yes, that works. I will also explore a PHP solution but the
javascript is working. Thanks!

Oct 13 '05 #4
Sandy Bremmer wrote:
On Wed, 12 Oct 2005 23:20:46 -0500, "McKirahan" <Ne**@McKirahan.com>
wrote:

[...]
<script type="text/javascript">
document.write("<a href='http://some.program.com/index.php?" + location.href
+ "'>link</a>");
</script>


Yes, that works. I will also explore a PHP solution but the
javascript is working. Thanks!


You could use an onload function that adds the current URI to every A
element's href attribute - a lot cleaner than using a script element
for every A element (and the links will still work without scripting,
although without the URI extension).
function addURI()
{
var allLinks = document.links;
var thisURI = location.href;
var x;
for (var i=0, j=allLinks.length; i<j; ++i){
x = allLinks[i];
if (x.href && '' != x.href){
x.href += '?'+ thisURI;
}
}
}

window.onload = addURI;


--
Rob
Oct 13 '05 #5

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

Similar topics

5
by: ashutosh.bhardwaj1980 | last post by:
Hi, I amdeveloping a web site in ASP and it is a secure site. I would like someone to help me on this: -->i dont want 2 users to accesss my site with the same username parallely. --> Also...
1
by: Rick Strahl [MVP] | last post by:
I often have the need to run templates that perform the equivalent of a mail merge as part of the processing for another page. For example, I have an invoice display page in my admin module and...
3
by: Greg Smith | last post by:
Hi, I have written several Windows based applications and I have always had an "application log" which captures username, machinename etc. As I now turn to web based applications I would like to...
8
by: Raj Thakkar | last post by:
Hi, I am currenty working on a site for intranet. I have a user control in the header of every page that will be displayed only if people with certain username are surfing the site. These lists...
10
by: Andrew | last post by:
Hi, I have a messagebox that pops up due to an event. I did it in javascript. ie. alert("Time's up. Assessment Ended"); I want to capture the OK and Cancel events of this alert messagebox. My...
6
by: Ed Leafe | last post by:
I've been approached by a local business that has been advised that they need to start capturing and archiving their instant messaging in order to comply with Sarbanes-Oxley. The company is largely...
1
by: praveenmmohanan | last post by:
Hi..., We have a pretty huge form where the user/support spends more than 6 minutes. Now, behind the scenes, I wanted to capture the outerHTML data & send it to a different URL to save it in...
6
by: =?Utf-8?B?Q2h1Y2sgUA==?= | last post by:
I have a Role Provider with a subdirectory protected via the web.config. Forms authentication is used. If a person who is not in the role tries to access a page in the directory, the browser is...
7
by: David Lozzi | last post by:
Howdy, I'm trying to capture the session end event. I put a spot of code in the Session_End event in the Global.asax.vb file. The function simply writes to a database table logging the event. I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.