javascript code

P

Peter

I have the following variable and I want to redirect to its location
at window.parent.location=Out but it doesn't work. I've tried it with
and without the ; semicolon. I've cleared my cache each time I
attempted to run the code otherwise it wouldn't get the new code. It
allows me to go to google.com so I know the window.parent.location
part is correct. When I do the document.write(out) it displays the
correct url so I know it contains the correct data so am stumped at
why window.parent.location=Out doesn't work.

Out='<font size=-2><a href="http://www.domain.com/csv/csvread.cgi?
mytemplate=tp4&type=RD&order_by=SORTORDER&DATE>='+Fmt+'">'+Fmt+'</
a><br>';

this doesn't work
window.parent.location=Out;

this works
window.parent.location="http://www.google.com"

this works
document.write(Out);

Any thoughts as whats wrong

Thanks,
Pete
 
E

Evertjan.

Peter wrote on 14 jan 2008 in comp.lang.javascript:
I have the following variable and I want to redirect to its location
at window.parent.location=Out but it doesn't work. I've tried it with
and without the ; semicolon. I've cleared my cache each time I
attempted to run the code otherwise it wouldn't get the new code. It
allows me to go to google.com so I know the window.parent.location
part is correct. When I do the document.write(out) it displays the
correct url so I know it contains the correct data so am stumped at
why window.parent.location=Out doesn't work.

Out='<font size=-2><a href="http://www.domain.com/csv/csvread.cgi?
mytemplate=tp4&type=RD&order_by=SORTORDER&DATE>='+Fmt+'">'+Fmt+'</
a><br>';

this doesn't work
window.parent.location=Out;

As it should.

location is short for location.href

window.parent.document.location.href = Out;

does expect Out to be a string containing an URL and only that.

Why do you think it could be a string containing html?
Because you think it fills the adressbar and then executes that?
If so you thought wrong.
this works
window.parent.location="http://www.google.com"

this works
document.write(Out);

Do you define "works" as
"does not give an error"
or
"does what I assumed it would do".

document.write(Out) just writes the html string to the dom,
but if the dom/page was already finished "loading in dom",
it will first destroy the rendered dom page and all that was in it
including the javascript.
Any thoughts as whats wrong

Do not assume, but read the specs in using statements in javascript.
 
R

RobG

I have the following variable and I want to redirect to its location
at window.parent.location=Out but it doesn't work.  I've tried it with
and without the ; semicolon.

Semicolons are irrelevant for a single line of code, they will be
automatically inserted when the code is parsed - but I prefer to add
them anyway.

 I've cleared my cache each time I
attempted to run the code otherwise it wouldn't get the new code.  It
allows me to go to google.com so I know the window.parent.location
part is correct.   When I do the document.write(out) it displays the
correct url so I know it contains the correct data so am stumped at
why window.parent.location=Out doesn't work.

Out='<font size=-2><a href="http://www.domain.com/csv/csvread.cgi?
mytemplate=tp4&type=RD&order_by=SORTORDER&DATE>='+Fmt+'">'+Fmt+'</
a><br>';

this doesn't work
window.parent.location=Out;

The location property is expected to be set to a URI, not a string of
HTML. See your own code below.
 
T

Thomas 'PointedEars' Lahn

RobG said:
The location property is expected to be set to a URI, not a string of
HTML. See your own code below.

It would appear that a URI reference suffices. Consider this:

window.parent.location = "../foo?bar#baz";


PointedEars
 

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

Forum statistics

Threads
473,787
Messages
2,569,627
Members
45,329
Latest member
InezZ76898

Latest Threads

Top