469,943 Members | 2,590 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,943 developers. It's quick & easy.

location.replace in a function

Hi everybody,
I have this function in a page (namely cours.html)

function go(inValue)
{
var lien =
'file:///F:/MyWebs/jeanpierredaviaucom/httpdocs/cours1.html?T1=' +
document.R.T1.value;
document.location.replace = "lien";
}
If I put an alert(lien), the link is ok. But when I try it I see
'file:///F:/MyWebs/jeanpierredaviaucom/httpdocs/cours.html?T1=' +
document.R.T1.value; in the address bar (the 1 dissappear and I have the
url of the page in wich the function is.)
--

X trême newbe
.......
masm32
windows Xp
asus p4 s533/333/133
Intel(R) Celeron (R) CPU 2.00 GHz
Nov 27 '05 #1
9 6485
Jean Pierre Daviau said the following on 11/27/2005 3:01 PM:
Hi everybody,
I have this function in a page (namely cours.html)

function go(inValue)
{
var lien =
'file:///F:/MyWebs/jeanpierredaviaucom/httpdocs/cours1.html?T1=' +
document.R.T1.value;
document.location.replace = "lien";
document.location.replace(lien)

<URL:
http://msdn.microsoft.com/library/de...ds/replace.asp


--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 27 '05 #2
"Randy Webb" <Hi************@aol.com> a écrit dans le message de news:
fp********************@comcast.com...
Jean Pierre Daviau said the following on 11/27/2005 3:01 PM:
Hi everybody,
I have this function in a page (namely cours.html)

function go(inValue)
{
var lien =
'file:///F:/MyWebs/jeanpierredaviaucom/httpdocs/cours1.html?T1=' +
document.R.T1.value;
document.location.replace = "lien";
there is a mistake here
document.location.replace(lien)

<URL:
http://msdn.microsoft.com/library/de...ds/replace.asp If I put an alert(lien), the link is ok. But when I try it I see
cours.html?T1=thevalue in the address bar (the 1 dissappear and I have
the url of the page in wich the function is.

I tried theese two ways without success.

function go(inValue){
document.location.replace('cours1.html?T1=' + document.R.T1.value)
}

<form name="R" onSubmit="history.go(document.location.href =
'cours1.html?T1=' + document.R.T1.value);">
Nov 28 '05 #3
Jean Pierre Daviau wrote:
I tried theese two ways without success.

function go(inValue){
document.location.replace('cours1.html?T1=' + document.R.T1.value)
}

<form name="R" onSubmit="history.go(document.location.href =
'cours1.html?T1=' + document.R.T1.value);">


history.go() expects a number as argument, indicating how far to go back
(less than zero) or forward (greater than zero) in the history, or "A
string representing all or part of a URL in the history list.". It is
completely useless here. RTFM, e.g.

<URL:http://ific.uv.es/informatica/manuales/ClientReferenceJS13/history.html#1193970>
PointedEars
Nov 28 '05 #4

"Thomas 'PointedEars' Lahn" <Po*********@web.de> a écrit dans le message de
news: 70****************@PointedEars.de...
Jean Pierre Daviau wrote:
I tried theese two ways without success.

function go(inValue){
document.location.replace('cours1.html?T1=' + document.R.T1.value)
}

<form name="R" onSubmit="history.go(document.location.href =
'cours1.html?T1=' + document.R.T1.value);">


history.go() expects a number as argument, indicating how far to go back
(less than zero) or forward (greater than zero) in the history, or "A
string representing all or part of a URL in the history list.". It is
completely useless here. RTFM, e.g.


I did not do javascript for some years. I should have remember that.

Thanks
Nov 28 '05 #5
The followin works, but the viewer has to accept the closing in IExplorer.
It seems inelegant.

<form name="R" onSubmit="var lien='cours1.html?T1=' +
document.R.T1.value;window.open(lien,'','');self.c lose();">
Nov 28 '05 #6
Jean Pierre Daviau wrote:
The followin works, but the viewer has to accept the closing in IExplorer.
And, hopefully, in many other browsers.
It seems inelegant.
It seems to be nonsense.
<form name="R" onSubmit="var lien='cours1.html?T1=' +
document.R.T1.value;window.open(lien,'','');self.c lose();">


Of course, that is a security measure to prevent loss of history and
browser control due to script kiddies.

If you would explain what you are trying to achieve, one might provide
a suggestion on how to achieve it best. So far, your source code does
not make any sense.
PointedEars
Nov 28 '05 #7
Thomas 'PointedEars' Lahn said the following on 11/28/2005 12:10 PM:
Jean Pierre Daviau wrote:

The followin works, but the viewer has to accept the closing in IExplorer.
They don't have to accept it, you just have to know how to prevent the
dialog box.

<snip>
<form name="R" onSubmit="var lien='cours1.html?T1=' +
document.R.T1.value;window.open(lien,'','');self .close();">

Of course, that is a security measure to prevent loss of history and
browser control due to script kiddies.


And to date, the only browsers that don't allow you to close a window
you didn't open is Mozilla based browsers. IE and Opera allow me to do
it. And I don't think I qualify as a "script kiddie".

And since that feature/bug has been around a lot longer than Mozilla has
it can stop being called a "bug" since even Opera allows it (in some
form or another).

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 28 '05 #8

"Lee" <RE**************@cox.net> a écrit dans le message de news:
dm*********@drn.newsguy.com...
Jean Pierre Daviau said:
I tried theese two ways without success.

function go(inValue){
document.location.replace('cours1.html?T1=' + document.R.T1.value)
}


How are you calling this function?
If it's in the onsubmit handler of your form, consider that you're
telling the browser to perform two conflicting actions:
1. submit the form, and load the resulting content
2. replace the page with your new URL

Right.
The following works.
<SCRIPT language="JavaScript">
if(getChip("webJPD", "passez")){
location.replace("cours1.html");
}
function go(inValue){
var lien= 'cours1.html?T1=' + inValue;
document.location.replace(lien);
}
</SCRIPT>
...
<body>
<form name="R">
<fieldset>
<legend>Mot de passe</legend>
<p><input type="text" name="T1" size="20"></p>
<P><INPUT TYPE="button" value="validate"
onClick="go(document.R.T1.value);"></p>
</fieldset>
</form>

'the script kiddy'
Nov 28 '05 #9
Jean Pierre Daviau wrote:
The following works.
Not reliably.
<SCRIPT language="JavaScript">
The `type' attribute value is missing for HTML 4, the `language'
attribute is deprecated there.

<URL:http://validator.w3.org/>
if(getChip("webJPD", "passez")){
location.replace("cours1.html");
}
function go(inValue){
var lien= 'cours1.html?T1=' + inValue;
document.location.replace(lien);
}
Location objects are host objects, you should test whether they are
supported and whether they provide a replace() method.

<http://www.pointedears.de/scripts/test/whatami>, § 2.

That said, the document.location reference is deprecated long since,
use window.location or location instead.
</SCRIPT>
..
<body>
<form name="R">
This is invalid as well, the `action' attribute value is missing.
<fieldset>
<legend>Mot de passe</legend>
<p><input type="text" name="T1" size="20"></p>
<P><INPUT TYPE="button" value="validate"
onClick="go(document.R.T1.value);"></p>
onclick="go(this.form.elements['T1'].value);"></p>

is standards compliant. Be sure to specify the default scripting language
via a `meta' element in the `head' element in either case. Furthermore,
those are not paragraphs, so using the `p' element in that way is
inappropriate.
</fieldset>
</form>

'the script kiddy'


My comment referred to the abuse of client-side scripting by irresponsible
people (so-called "script kiddies"), especially those who seek to
manipulate the working environment of users, including trying to close
windows not opened with scripting, without their explicit consent. Unless
you use the above source code uncorrected in a public Web document, it
would not qualify as such and hence you would not.
PointedEars
Nov 29 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Andoni | last post: by
2 posts views Thread by James Marshall | last post: by
1 post views Thread by David T. Smith | last post: by
2 posts views Thread by brian | last post: by
10 posts views Thread by Roland | last post: by
2 posts views Thread by JHB | last post: by
13 posts views Thread by John Smith | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.