Solved

Stop JavaScript Running

Posted on 2004-03-26
7
10,052 Views
Last Modified: 2013-11-19
I have a script which runs and checks a user is not trying to get to pages in my site by purely entering the URL in the address bar. If they have got to the page in this way the script below "breaks" the frames and returns them to the login page. Works great except on a page where I have some client side script that runs to update another frame when the main page has finished loading. In this case i get errors popping up presumably because the second script has ran without the rest of the page being written and therefore cannot pass the variable information as part of the querystring (see below).

So ... heres the question ... is it possible to tell the javascript at the top of the page to stop running anything else in the current page including the location.href bit at the bottom ?

Script in header of all pages :
-----------------------------------

<script language="javascript">
if (window.location != top.location)
   top.location = window.location;
   location.href = "/myweb/";
</script>

Problem Script which runs on certain pages :
----------------------------------------------------
<script language="VBScript">
      parent.frames("topFrame").location.href = "TopFrame.asp?hdnID=" & document.frmResults.hdnID.value
</script>
0
Comment
Question by:robert_f
  • 3
  • 2
  • 2
7 Comments
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10687832
<script language="javascript">
    setTimeout('parent.frames("topFrame").location.href = "TopFrame.asp?hdnID="+document.frmResults.hdnID.value',200)
</script>
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10687919
sorry missed a quote

 <script language="javascript">
   setTimeout('parent.frames("topFrame").location.href = "TopFrame.asp?hdnID="'+document.frmResults.hdnID.value+'',200)
</script>
0
 

Author Comment

by:robert_f
ID: 10687967
Jay

Thanks mate ... but unfortunately its still doing the same thing (just pauses briefly before erroring now instead :-) ) .

Cheers

Rob
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 25

Expert Comment

by:devic
ID: 10692138
-----------
if (window.location != top.location)
  top.location = window.location;
-----------
the code above is "frames killer"




and the code below works with frames...
------------
parent.frames("topFrame").location.href = "TopFrame.asp?hdnID=" & document.frmResults.hdnID.value
-----------

they can not work together

0
 

Author Comment

by:robert_f
ID: 10694475
Devic

I think I understand what your saying ..... however the problem is the "frame code" needs to be there for when the page runs legitimately .... problem seems to be that the "frame killer" code runs OK but the rest of the page continues to run and as you have quite rightly said it cannot access the topframe because its already broken out. What I wanted was some method of stopping the rest of the page/code running once the frame killer code has run to stop this happening. Might be I'm missing something fundamental in all this which will not allow it happen ... if so I apologise in advance for my stupidity :-) The way I thought it worked was :

1.  top.location = window.location "breaks" the frame set.
2.  location.href = "/myweb/" sets the new page you want displayed (before loading the rest of the existing page)

What seems to happen though is the frameset is broken then the VBScript at the bottom of the original page tries to run before the "new" page is set.

Hope this makes sense.

Cheers

Rob

0
 
LVL 25

Accepted Solution

by:
devic earned 125 total points
ID: 10694652
hi Rob,

you can always check if the frame exists:
============
<script>
if(parent.frames.topFrame)
{
      parent.frames.topFrame.location.href = "TopFrame.asp?hdnID=" + document.frmResults.hdnID.value;
}
</script>
0
 

Author Comment

by:robert_f
ID: 10694942
Devic

Excellent mate ...  works great !! Thanks for your help.

Cheers

Rob
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now