?
Solved

Stop JavaScript Running

Posted on 2004-03-26
7
Medium Priority
?
10,065 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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 500 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

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 …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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 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…
Suggested Courses

801 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