Solved

Stop JavaScript Running

Posted on 2004-03-26
7
10,047 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
Comment Utility
<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
Comment Utility
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
Comment Utility
Jay

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

Cheers

Rob
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 25

Expert Comment

by:devic
Comment Utility
-----------
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
Comment Utility
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
Comment Utility
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
Comment Utility
Devic

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

Cheers

Rob
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
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.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 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

15 Experts available now in Live!

Get 1:1 Help Now