/    Sign up×
Community /Pin to ProfileBookmark

Sending referer URL to Form element

I want to be able to send the URL (and preferably just a segment of the URL – namely the html filename) to a form and have it entered as a text field value.

The same form page will be accessed from multiple prouct pages and it is important that the product page that the user came in from be added to the form data.

Is this possible?

Steve (aka Javadog)

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@StashXJan 18.2005 — do you mean that you want to have in a text fild the url(html name) of the page that send a user to that page???
Copy linkTweet thisAlerts:
@javadogauthorJan 18.2005 — Yes. That is exactly what I mean.

Steve
Copy linkTweet thisAlerts:
@StashXJan 18.2005 — I don't remember if is posible and how to take the url of a history page BUT you can do that if your page is opened to a new window....

Page1 (Opener):
[CODE]<html>

<head>
<title>tPage1</title>
</head>

<body>

<p><a target="_blank" href="Page2.htm">Open Page2.htm in new window</a></p>
<p><a href="Page2.htm">Open Page2.htm in same window</a></p>

</body>

</html>[/CODE]


Page2 (Your Page):
[CODE]<html>

<head>
<title>Page2</title>
</head>

<body>

<form name="form_name">
<p><input type="text" name="fild_name" size="50"><p>
</form>
<script language="javascript">
if (window.opener){
form_name.fild_name.value=window.opener.location.pathname;
}
else{
form_name.fild_name.value="";
}
</script>
</body>

</html>[/CODE]
Copy linkTweet thisAlerts:
@javadogauthorJan 18.2005 — I would like it if the page did not have to open a new window. Could the value history(-1) be used within this code somehow?

Steve
Copy linkTweet thisAlerts:
@StashXJan 18.2005 — try this....

I just found it in my files....

Localy it doesn't work but if you upload the page it must work....
[CODE]<html>

<head>
<title>Page2</title>
</head>

<body>

<form name="form_name">
<p><input type="text" name="fild_name" size="60"></p>
</form>
<script language="javascript">
if (window.opener){
form_name.fild_name.value=window.opener.location.pathname;
}
else{
form_name.fild_name.value=document.referrer;

}
</script>
</body>

</html>[/CODE]
Copy linkTweet thisAlerts:
@PittimannJan 18.2005 — Hi![i]Originally posted by javadog [/i]

[B]I would like it if the page did not have to open a new window. Could the value history(-1) be used within this code somehow?



Steve [/B]
[/QUOTE]
You cannot access the urls contained in the history array. But (as far as the server sends it), you can use document.referrer to get the referring page. I put a little example here: http://www.pit-r.de/scripts/referrerFrom.htm

Cheers - Pit
Copy linkTweet thisAlerts:
@javadogauthorJan 18.2005 — That solution works great. Thanks Pittimann. One more question. Is ther any way to strip the file extension .htm from the variable?

Steve

PS Thanks StahX for your input.
Copy linkTweet thisAlerts:
@StashXJan 19.2005 — yes,by using [b].replace(".htm","")[/b]
[CODE]<html>

<head>
<title>Page2</title>
</head>

<body>

<form name="form_name">
<p><input type="text" name="fild_name" size="60"></p>
</form>
<script language="javascript">
if (window.opener){
form_name.fild_name.value=window.opener.location.pathname[b].replace(".htm","")[/b];
}
else{
form_name.fild_name.value=document.referrer[b].replace(".htm","")[/b];

}
</script>
</body>

</html>[/CODE]
Copy linkTweet thisAlerts:
@javadogauthorJan 20.2005 — Thanks again StashX.

Steve
×

Success!

Help @javadog spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...