Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing Javascipt Inside an ASP Page

Status
Not open for further replies.

rhnewfie

Programmer
Jun 14, 2001
267
CA
I am having an issue trying to get my asp page to write a javascript function. I get a Nested Script Block error when trying to execute the following:

Response.Write("<HTML>")
Response.Write("<HEAD>")
Response.Write("<TITLE>Title</TITLE>")
Response.Write("<script language=javascript>")
Response.Write("function loadMain(){")
Response.Write("parent.main.location=Main.asp")
Response.Write("}")
Response.Write("</script>")
Response.Write("</HEAD>")
Response.Write("<BODY>")

etc...

Any ideas would be great!
 
Not sure that this would act any differently but is worth a shot.

Code:
myscript=""
myscript=myscript&"<script language=javascript>"&vbCrLf
myscript=myscript&vbtab&"function loadMain(){"&vbCrLf
myscript=myscript&vbtab&&vbtab&"parent.main.location=Main.asp"&vbCrLf
myscript=myscript&vbtab&"}"&vbCrLf
myscript=myscript&"</script>"

Response.Write("<HTML>"&vbCrLf)
Response.Write("<HEAD>"&vbCrLf)
Response.Write("<TITLE>Title</TITLE>"&vbCrLf)
Response.Write(myscript&vbCrLf)
Response.Write("</HEAD>"&vbCrLf)
Response.Write("<BODY>"&vbCrLf)
'etc...

-a6m1n0

Curiosity only kills cats.
 
If you look at the actual HTML output, you may see what the problem is. Also, you'll probably want to add single quotes around the URL you assign to parent.main.location to make it work correctly.

Lee
 
I've got to ask the question.

Why are you using asp to write a javascript redirect?

response.redirect("main.asp") does exactly what you need.

unless of course you are coding a "poor mans cloaking" script

Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 
Writing out the script tag complete can cause the problem.
You are better off breaking it up so that the ASP side does not interpret the script tag, only writes it to the page where the browser will interpret it.

Code:
Response.Write "<SCR" & "IPT LANGUAGE=""JavaScript"">" & vbCrlf
Response.Write("function loadMain(){")
Response.Write("parent.main.location=Main.asp")
Response.Write("}")
Response.Write "</SCR" & "IPT>" & vbCrlf

It's probably a good idea to update the script tag to read:
Code:
"<SCR" & "IPT type=""text/JavaScript"">" & vbCrlf



It's hard to think outside the box when I'm trapped in a cubicle.
 
Chris - I need a secondary frame to get loaded when I load the primary frame. My thought was to use a body onLoad() to call the javascript to load the secondary frame. If there is a better way to do it I am all ears!

What is a poor mans cloaking script?

I will try the suggestions above though.

Thanks All!!
 
poor mans cloaking" refers to the doorway page tactics used for SE deception.
The SE crawler doesn't trigger the javascript so browsers see one page, users see another. It's an old tactic easy to find and penalise.

If there is a better way to do it I am all ears
Yep, Use Self Referencing Framesets

Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top