/    Sign up×
Community /Pin to ProfileBookmark

Help with a simple Java script

Hello

I wondered if someone could help. In the past I have used this small script:

<SCRIPT LANGUAGE=”JavaScript”>
<!– if (top.location.href.indexOf(“mypage.html”) == -1)
top.location.href = “mypage.html?pageURL&frameNum”;
// –>
</SCRIPT>

to reload a HTML page in a frame’s html I specify. It has worked very well for me.

I now want to use the same little script in a cgi file that will load a frame page on creation so the cgi page is displayed in the correct frame work.

However, the script above, once placed in the cgi file, causes the page to refresh over and over in a continuos loop.

How do I modify the script to stop the reload once the page has been loaded into the framework?

Hope someone can help

cheers Jordy ?

to post a comment
JavaScript

17 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliAug 11.2004 — it sounds like page is being submitted to your CGI or server side everyt time,you need to make sure that when you call this code does not submit itself to your CGI....
Copy linkTweet thisAlerts:
@JordyauthorAug 12.2004 — Hi there,

thanks for the response. The whole web page and subsequent web pages are generated by a cgi script., there are no raw or template html files which the cgi script interactives with. Every page you see displayed on screen is outputed by the CGI script. So the little head script to force the framework is entered into the raw html inside the cgi script. This is why I need to terminate the script after it reloads once. As it stands now, it loops continously as the page is reloaded.

So I just need to change the script some how, to instruct it to say 'loop once and then stop/exit' or whatever. Can this be done? I'm very new to Java and coding as a whole so feel free to explain things in it's basic terms.

Hope you can help

Jordy
Copy linkTweet thisAlerts:
@KorAug 12.2004 — Hm... try another small redirector as:
[code=php]
<html>
<head>
<script>
function redir(){
if(parent.frames.length==0){
window.location="index.html";
}
}
</script>
</head>
<body onload="redir()">
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@JordyauthorAug 12.2004 — Hi Kor

You are a star, that worked a treat! The page only loads once and if the frame isn't detected it reloads in the frame work and then stops.

Many thanks

Jordy
Copy linkTweet thisAlerts:
@CharlesAug 12.2004 — Hey Kor, please use valid HTML in your posts. You're only confusing the newbies.

[font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<title>Example</title>

<script type='text/javascript">

function redir(){

if(parent.frames.length==0){

window.location="index.html";

}

}

</script>

</head>

<body onload="redir()">

</body>

</html>[/font]
Copy linkTweet thisAlerts:
@Willy_DuittAug 12.2004 — [i]Originally posted by Charles [/i]

[B]Hey Kor, please use valid HTML in your posts. You're only confusing the newbies.[/B][/QUOTE]


I'm sure Kor's example usage was to merely intended to clarify that the script belonged in the [b]HEAD[/b] as well as noting that there was a function call on [b]body.onload[/b]...

However, if we are going to take the moral highground demonstrating [i]valid HTML[/i] and using a strict.dtd, lets not forget the [b]CDATA[/b].... ?

[font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<title>Example</title>

<script type=[b][color=red]'[/color][/b]text/javascript">

[color=red]<![CDATA[[/color]

function redir(){

if(parent.frames.length==0){

window.location="index.html";

}

}

[color=red]]]>[/color]

</script>

</head>

<body onload="redir()">

</body>

</html>[/font]

Cheers;

.....Willy
Copy linkTweet thisAlerts:
@CharlesAug 12.2004 — Mr. Duitt, now you're confusing XHTML with HTML. And you'll end up with something that will confuse a lot of browsers.
Copy linkTweet thisAlerts:
@Willy_DuittAug 12.2004 — No I'm not. [url=http://www.thozie.de/english/mobileweb/markup/structure.htm]Here is a quick reference link[/url]. Scroll down to where it outlines [b]Script[/b]....

.....Willy
Copy linkTweet thisAlerts:
@CharlesAug 12.2004 — [i]Originally posted by Willy Duitt [/i]

[B]No I'm not. [url=http://www.thozie.de/english/mobileweb/markup/structure.htm]Here is a quick reference link[/url]. Scroll down to where it outlines [b]Script[/b]....



.....Willy [/B]
[/QUOTE]
There's nothing on that page about marking the contents of the SCRIPT element as CDATA. In fact, there's nothing there at all what the elements contain. It's just a list of the elements and their attributes and at that it's incorrect and incomplete. Any idiot can, and often does, upload some document that reflects what they feel HTML is.

The actual specification for HTML can be found at http://www.w3.org/TR/html4/. Please read that a couple of times before you post anything else.

On a personal note, I don't trust my own memory so most always, when I'm posting to this board, I have the spec. open in another window. I like to double check everything that I post.
Copy linkTweet thisAlerts:
@Willy_DuittAug 12.2004 — [i]Read a couple of times[/i] LOL

pfhhtttttttt

Excuse meeee....

Ok, you are the resident guru....

Sorry I stepped on your toes but your wrong....

If you are going to take the moral high ground you should at least do it correctly. Comment tags are still recommended. However, the comment tags as you know them have long ago been deprecated in favor of CDATA much the same as language was long ago deprecated in favor of type. But I'm not inclined to get in a pissing contest with you nor do I have the time to search for any additional links, however I do concede that the link I provided was less than desirable to support my position....

.....Willy
Copy linkTweet thisAlerts:
@KorAug 12.2004 — Tx Willy, u were right... I intended just to show Jordy that the script should be fired onload, without care (sorry Charles) about the coding strictness (which is subject to be changed in a minute, anyway, if you opened that small quarell)

?
Copy linkTweet thisAlerts:
@CharlesAug 12.2004 — [i]Originally posted by Willy Duitt [/i]

[B]Comment tags are still recommended. However, the comment tags as you know them have long ago been deprecated in favor of CDATA much the same as language was long ago deprecated in favor of type. But I'm not inclined to get in a pissing contest with you nor do I have the time to search for any additional links, however I do concede that the link I provided was less than desirable to support my position....



.....Willy [/B]
[/QUOTE]
You are quite right that you don't have the time to find an authority depricating comment tags in favor of indicating CDATA sections. There isn't enough time in the world; it doesn't exist.

XML, and therefore XHTML&trade;, still employs the SGML/HTML comment tags - though not the SGML attribute like comments. Hence the HTML Compatibility Guideline "C.4. Embedded Style Sheets and Scripts" from the XHTML&trade; 1.0 specification:[b]Use external style sheets if your style sheet uses < or & or ]]> or --. Use external scripts if your script uses < or & or ]]> or --. Note that XML parsers are permitted to silently remove the contents of comments. Therefore, the historical practice of "hiding" scripts and style sheets within "comments" to make the documents backward compatible is likely to not work as expected in XML-based user agents.[/b]

[i]http://www.w3.org/TR/xhtml1/#guidelines[/i][/quote]
Note: that applies to XHTML&trade;; it doesn't apply to HTML and HTML hasn't been depricated. And note, the CDATA section is not a comment, nor is it required for every script or style sheet. (See http://www.w3.org/TR/2004/REC-xml-20040204/#sec-cdata-sect in the XML Specifications if your contempt for specifications will permit it.) It simply tells the parser that what is contained is character data (CDATA) and not markup. It's sort of like the old MSIE XMP element. And in this case, where we have nothing that looks like markup, we wouldn't need to mark it as CDATA.
Copy linkTweet thisAlerts:
@CharlesAug 12.2004 — [i]Originally posted by Kor [/i]

[B]Tx Willy, u were right... I intended just to show Jordy that the script should be fired onload, without care (sorry Charles) about the coding strictness (which is subject to be changed in a minute, anyway, if you opened that small quarell)



? [/B]
[/QUOTE]
In the same way that you need to watch you language in front of small children, you need to watch your mark up language in front of beginners.

If you don't know what a valid HTML document looks like, please at least use the required "type" attribute with your SCRIPT elements.
Copy linkTweet thisAlerts:
@KorAug 13.2004 — 
in front of beginners.
[/quote]

There is no track for I or you can presume Jordy is a begginer. I always let the others to use whichever mark up they want. I am not here to be pedantic but to give quick solutions to a certain problems, according to my knowledge.


If you don't know what a valid HTML document looks like, please at least use the required "type" attribute with your SCRIPT elements.
[/quote]


With all my respect, I must let you know that, untill the moment you will be the moderator of this section, I will keep my liberty of follow or to ignore your pathetic and pedantic messages ? . As you are not my teacher, I reckon you missed the class.?

With the same respect, I still guess that you might use your energy for solving problems rather that to criticize the strictless coding of others (strictness which is anyway not so absolute as you appear to be so convinced of).
Copy linkTweet thisAlerts:
@steelersfan88Aug 13.2004 — Well I think the other way around is much more reliable. Never miss anything Chuck says because he can always help you improve, and never listen to the modeerators.

... Just my way of living in these forums.
Copy linkTweet thisAlerts:
@CharlesAug 13.2004 — [i]Originally posted by Kor [/i]

[B]There is no track for I or you can presume Jordy is a begginer. I always let the others to use whichever mark up they want. I am not here to be pedantic but to give quick solutions to a certain problems, according to my knowledge.







With all my respect, I must let you know that, untill the moment you will be the moderator of this section, I will keep my liberty of follow or to ignore your pathetic and pedantic messages ? . As you are not my teacher, I reckon you missed the class.?



With the same respect, I still guess that you might use your energy for solving problems rather that to criticize the strictless coding of others (strictness which is anyway not so absolute as you appear to be so convinced of). [/B]
[/QUOTE]
Jordy isn't the only potential beginner reading this thread.

It is the job of any engineer or architect to solve the client's problem, [i]without causing any unforeseen and unfortunate side effects[/i]. To that end we have building codes. (And doctors pledge, as a part of their oath, to do no harm.) In like manner, web pages have building codes: the HTML 4.01 spec. and the Web Content Accessibility Guidelines 1.0.

The "type" attribute is required with the SCRIPT element for a reason; no default scripting language is defined by the specs. Your example won't work on a browser that defaults to TCL, for example. And yes, I have seen such a browser.
Copy linkTweet thisAlerts:
@KorAug 13.2004 — But I never said I don't use type or marks (you should have search for all my posts to see that)... It's just that, this time, I wrote very quickly the code guessing that the main thing is the code itself...

So, I did not say that you are not right. It is just that I don't believe it was necessary to specify all the marks ant types at the moment, that is all.

Most of the time people just copy the line codes, so you will never know which kind of marks or type are really using on their page. Sure they must use them, but, I repeat, I don't think that this is the main meaning of this forum...

Once again, sure, you are right, they must code HTML tags and marks in a correct mode.
×

Success!

Help @Jordy 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.20,
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,
)...