Solved

Stop JavaScript Running

Posted on 2004-03-26
7
10,050 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

895 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

12 Experts available now in Live!

Get 1:1 Help Now