Solved

Stop JavaScript Running

Posted on 2004-03-26
7
10,061 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
The viewer will learn how to count occurrences of each item in an array.
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…

705 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