PDA

View Full Version : block back button


scriptblur
11-15-2002, 02:38 AM
Hi guys.... please help...


does anyone know how to prevent users from returning to their previous pages where they have came from.... every suggestion welcome.... thank a lot.

glenngv
11-15-2002, 03:08 AM
put this on the page you don't want the user to go back to:

<script language="javascript">
history.forward();
</script>

cg9com
11-15-2002, 05:43 AM
should we answer questions in html 4.01 or xhtml 1.0 ?

in the xhtml case language="javascript" is deprecated
and type="text/javascript" should replace it

scriptblur
11-15-2002, 06:20 AM
ok.. thank... got it..

can response.redirect like the normal <a href="../asp.asp" target="_parent"></a>?? so that the page been redirected will be on a new page instead of having the frame border on top...

scriptblur
11-15-2002, 06:54 AM
ok.. thank... got it..

can response.redirect like the normal <a href="../asp.asp" target="_parent"></a>?? so that the page been redirected will be on a new page instead of having the frame border on top...

glenngv
11-15-2002, 07:16 AM
since response.redirect is a server-side script, it will always open the page specified in the same window. it doesn't know the "window structure" since this is client-side. Using server-side code, however, you can output html and javascript that can open the page in a new window or frame.


<%
'other codes here
page = "page.asp" 'sample page to be redirected to another window/frame
%>
<html>
<head>
<script language="javascript">
window.onload=function(){
setTimeout("window.open('<%=page%>','frameNameHere')",3000); //3000 = 3 secs
}
</script>
</head>
<body>
The page will be opened to a new window/frame.<br>
Click <a href="<%=page%>" target="frameNameHere">this</a>
if you do not want to wait any longer or if the page is not opened.
</body>
</html>
<%
response.end 'dont forget this if you have other codes below
%>


is this what you wanted?

scriptblur
11-15-2002, 07:23 AM
Hi glenn... thank for the help...

but actually i wanted to do something like this:
when the users click the back button, it will be redirected to another page. however this page has two frames and i want the page to be by itself instead of an extra frame above. can i do something to the response.redirect"../staff/staff_content.asp" so that it can appear in one whole page. like <a href ="..." targaet="_parent">?



Response.Buffer = True
Response.ExpiresAbsolute = Now() - 1
Response.Expires = 0
Response.CacheControl = "no-cache"

If Len(Session("FirstTimeToPage")) > 0 then

Session("FirstTimeToPage") = ""
Response.Redirect "../staff/staff_content.asp"
Response.End
End If

glenngv
11-15-2002, 07:48 AM
try this:


<%
Response.Buffer = True
Response.ExpiresAbsolute = Now() - 1
Response.Expires = 0
Response.CacheControl = "no-cache"

If Len(Session("FirstTimeToPage")) > 0 then

Session("FirstTimeToPage") = ""
page = "../staff/staff_content.asp"

%>
<html>
<head>
<script language="javascript">
window.onload=function(){
setTimeout("window.open('<%=page%>','_top')",3000); //3000 = 3 secs
}
</script>
</head>
<body>
The page will be opened without frames.<br>
Click <a href="<%=page%>" target="_top">this</a>
if you do not want to wait any longer or if the page is not opened.
</body>
</html>
<%
response.end
end if
%>

whammy
11-16-2002, 01:28 AM
To cg9com, since it is backwards compatible, I gladly agree with using:

<script type="text/javascript">

instead of:

<script language="javascript">

or (redundant, but I've seen it a lot):

<script language="javascript" type="text/javascript">

Although, you can define the default scripting language for the page in a META tag as well, and just use <script>.

I just don't see any reason to promote outdated practices. so YES, use that in your future scripts and posts - if we don't get the browser makers to conform to standards, they aren't really standards. Which is another reason to avoid using proprietary commands (although it seems they are waking up, they are not as common now!) :)

realisis
11-16-2002, 06:31 PM
Why is language deprecated? That attribute is used to specify the minimum JS version, though as far as I know you cannot do this with the type attribute.

I submit that the following is not redundant:

<script language="JavaScript1.5" type="text/javascript">
//browsers which don't have JS 1.5 onboard will ignore the contents of this script
</script>

...

"Although, you can define the default scripting language for the page in a META tag as well, and just use <script>. "

Yes, I use the following on all my pages:

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

No problems, though I should mention that if you query the "type" property for a script in IE5.5, it's empty unless this was specified directly in the SCRIPT tag...

joh6nn
11-16-2002, 07:11 PM
realisis, have you ever actually seen the language attribute in use? i've only ever seen it on pages where the code was copied & pasted, by someone who didn't know what was going on. personally, i've never had a need for it.

there was also a huge problem with it: NS4. in NS4, if you set the language attribute to 1.2, then a whole bunch of things no longer work according to the standard. i've heard that somethings, no longer work at all ( though that's not a huge deviation from the norm, in NS4 ). so the very first set of browsers ( IE4 & NS4 ) in which you can even use the language attribute, it doesn't even do anything useful.

::shrug:: i won't miss it.

RadarBob
11-16-2002, 07:48 PM
I've read that if one types "language='javascript1.2'" for example that the browser will limit itself to JS 1.2 functionality. I've also read that "language="javascript", w/o any version will automatically default to JS 1.0. However I don't see it working that way in the web page I deal with using IE 5.5. I've made significant JS modifications with stuff that's in JS1.3 and above and, in IE 5.5 at least, things are working.

The key seems to be which (highest) version of JS the browser was built to support.

realisis
11-20-2002, 12:58 PM
"i've only ever seen it on pages where the code was copied & pasted, by someone who didn't know what was going on. personally, i've never had a need for it."


joh6nn,

Yes, but it wasn't the person who doesn't know what's going on who added the language attribute on those pages, it was the person who wrote the script, and who presumably does know what's going on.

Anyway, I've never used it myself, but when I first posted I was in the middle of a script problem and wasn't able to follow up until last night. And the solution to the problem was to use the language attribute.

The situation: browsers which use the modern Gecko engine (K-Meleon, Konqueror, Galleon also?) seem to have a serious problem accessing the BarProps objects, and they throw exceptions if you try to query each bar's "visible" property.

So I used a try/catch block to catch the error and prevent those browser from hanging.

Problem is, the words "try" and "catch" are reserved in Netscape 4 - you can't even use these keywords in a script, otherwise Netscape then throws an error, or displays other strange behaviour.

Even if you try to sniff out NS4 so that it doesn't process the try/catch block like this:

if(!document.layers)
{
try{ etc... }
catch(e) { etc... }
}

else { etc }

the browser still parses the relevant lines, and behaves as previously.

So one solution is to prevent NS4 from seeing the code at all, by embedding the script in a tag with language="JavaScript1.5".

So in this case at least, the language attribute had the intended effect, and it is useful after all.

realisis
11-20-2002, 01:11 PM
besides which, don't you think it is strange that there is still no javascript navigator property to reveal which version of javascript is supported by a browser?

Something like

navigator.jsVersion

would be very useful too.

joh6nn
11-20-2002, 03:42 PM
if you need that, then do this:

<script language="JavaScript1.0">
var jsV = 1.0;
</script>
<script language="JavaScript1.2">
var jsV = 1.2;
</script>
<script language="JavaScript1.3">
var jsV = 1.3;
</script>
<script language="JavaScript1.5">
var jsV = 1.5;
</script>
<script>
alert(jsV);
</script>

brothercake
11-20-2002, 05:09 PM
I use the language attribute all the time - always 1.2, because I know from that that browsers earlier than v4 will not attempt to process the script. That's a very useful safety net.

realisis
11-26-2002, 05:45 AM
btw, joh6nn, thanks for the tip - I believe the technique you mention is discussed in Netscape's JS1.3 manual, but I had forgotten about it. Of course, it doesn't help with the situation I described vis-à-vis NS4, but it'll be useful at some point or other.

Incidentally, though JS1.4 was released only in a server-side edition (as far as I know), adding it in revealed something curious: Opera 6.0 identifies itself as JS 1.4!

Even more curious: as per the technique you suggested, IE 5.5 identifies itself as JS1.3 (which suggests it couldn't read the variable's value in the "higher" language scripts). And yet, in the original example I gave, IE correctly reads the contents of a 1.5 script without hiccups.

...

RadarBob: "The key seems to be which (highest) version of JS the browser was built to support."

Yes, that's it. Specifying JS1.3 is intended to exclude browsers having JS versions lower than 1.3, but not higher than 1.3.

...

brothercake: "I use the language attribute all the time - always 1.2, because I know from that that browsers earlier than v4 will not attempt to process the script. That's a very useful safety net."

Uh-oh, I think you're on the bottom of joh6nn's dung heap now!! ;^]

Seriously though, joh6nn makes a good point regarding 1.2: when Netscape released 1.3 a number of "reversals" were made, with the result that certain behaviours exist only in 1.2, but not 1.1 or 1.3 etc... Ever run into any problems?


...

ps: my apologies for the late response to anyone's contribution - the last 10 days or so have been fairly hectic for me, and I'm just now finding the time to follow-up on any correspondence....