Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

STOP Other pages loading once main is loaded ?

Posted on 2004-10-23
19
Medium Priority
?
2,212 Views
Last Modified: 2010-05-18
Hi Guys:

What I wanted to do was the following... On some of my pages, they may be loaded within a frameset and at some point, I want one of those pages to detect when it has loaded and to then "STOP" loading anything else..

I have noticed that when you click the stop button in IE, it does this and prevents any other code in any other frame from loading (IE: If it was a timed event, it still doesn't load)...

Now I'm aware of such events as window.stop() and execCommand('Stop') but these don't provide the same result as clicking on the stop button in your browser...

So, How can I emulate this type of event ? The down side is, if you have any animated gif, it also kills this which I DONT want to happen ?
0
Comment
Question by:hollstar
[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
  • 6
  • 4
  • 3
  • +2
19 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 12391369
You can try this in your child window:

function stopOtherFrames() {
   for (var i=0;i<parent.frames.length;i++) {
      parent.frames[i].stop();
   }
}

Although I don't know if this will kill animated gif or not...
0
 

Author Comment

by:hollstar
ID: 12391563
I got a debug error trying to use the stop command which as I understand, is for Netscape only... Regardless, using the IE version doesn't work either... The main pages code is as follows... Maybe this will help ? Because if I try and run your code, it detects only one page not the one below which doesn't have a specific name ?



<body leftmargin="0" marginheight="0" marginwidth="0" scroll="no" topmargin="0">
<iframe frameborder="0" height="100%" name="Google" src="http://www.google.com" width="100%">
<script language="JavaScript">
location = "http://www.google.com";
</script>
<noscript>
<p><a href="http://www.google.com">http://www.google.com</a></p>

</noscript>
</iframe>
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12391593
Ah, you're talking about iframes, then you can try this (no guarantees):

function stopPageFrames() {
   for (var i=0;i<window.frames.length;i++) {
      window.frames[i].stop();
   }
}
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12391605
.stop() is Netscape only , for IE use

<body onload="for (i=0;i<top.frames[i].length;i++){top.frames[i].document.execCommand('Stop')}">


for cross browser use this

<script>
function stopLoad(){
  if (!document.all)
    for (var i=0;i<top.frames.length;i++)
      top.frames[i].stop()
  else
    for (var i=0;i<top.frames.length;i++)
      top.frames[i].document.execCommand('Stop')
}
</script>
<body onload="stopLoad() ">


</body>

0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12391613
Ah, thanks for that, I've never had to use window.stop heh
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12391634
 For iframes you must put the script at the end of the body as the iframe loading  is considered part of the page loading, the src of the iframe must be from the same domain, eg

<script>
function stopLoad(){
if (!document.all)
    for (var i=0;i<window.frames.length;i++)
      window.frames[i].stop()
  else
    for (var i=0;i<window.frames.length;i++)
      window.frames[i].document.execCommand('Stop')
 
}
</script>

<body>
  <iframe name=i1 src="http://myDomain.com/page1.htm"></iframe>
  <iframe name=i2 src="http://myDomain.com/page2.htm"></iframe>

<script>
  stopLoad()
</script>
</body>

0
 

Author Comment

by:hollstar
ID: 12392015
The code I posted above was running on one page...

What I want to do is on the code it loads within the new frame (not on that same page) is once it detects its loaded, it stops loading everything else... So the page loads the iframe, and at the end of THAT page, it stops... So anything else on that page which executed the iframe, no longer loads ? Is *this* possible ?
0
 
LVL 2

Expert Comment

by:ChrisDrake
ID: 12392480
might do nothing or not work - but how about trying the Go(0) call ?

If that doesn't work - this hack prolly will -

set the onload handler to load a new (_top) page containing the same stuff as your current page, with an extra bit on the url (eg: if your main frameset is blah.com/test.cgi then make it go to blah.com/test.cgi?reloaded)

Next - when the new page loads and sees "?reloaded" in the URL, it can do a go(-1)

You gotta somehow stop the 1st page going back to the 2nd again tho (cookies?)

With the correct use of caches, this will be fast.

It will work because when IE is told to load a new page, it cancels loading the existing one.

You might also be able to tell it to load a page which you know in advance will never exist, then cancel that loading (stop) before it produces an error (eg: there's a load of IP addresses that do not exist - so trying to load one of those will cancel the current load, and then "do nothing" until the connection times out)
0
 

Author Comment

by:hollstar
ID: 12392610
Go(0) Call ?

Can't say I have heard of this one mate ? Care to explain it... :-)
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12393434
hollstar,  I can stop any page loading (cross browser) but I have to know what the frames are and what the windows are  (and which window opened which if you have popups). At the moment the problem is muddled, if you are more precise about your set up  I can give you the code.
0
 

Author Comment

by:hollstar
ID: 12395387
The code I posted above is the main page but does not have any title or frameset name other than the iframe it loads which in my example was 'Google'. Now any of the code above will only detect the existance of 'Google' and not the page it was loaded from.

What I'm trying to do is detect that initial page (the one without a name), and prevent any further code from loading but do it all from that iframe... If its possible (which I dont think it is) Im assuming running the stop command will prevent any further code on that page from loading ?
0
 
LVL 2

Expert Comment

by:ChrisDrake
ID: 12396588
I forget exactly - history.go(0) or window.go(0) or something.  Check the MSDN site
0
 

Author Comment

by:hollstar
ID: 12410730
ChrisDrake: The Go option was an excellent idea, but didn't work... I understand the theory behind your next idea, but could you maybe explain it in a little more detail ? Or even provide an example if at all possible ?

Regards,

Hollstar
0
 
LVL 31

Accepted Solution

by:
GwynforWeb earned 2000 total points
ID: 12418331
If you are trying to stop the main page loading once an iframe has loaded than this does it (cross browser)

<script>
function stopLoad(){
if (!document.all)
  window.stop()
else
  window.document.execCommand('Stop')
}
</script>
<IFRAME src="http://google.com" onload="stopLoad()"></IFRAME>
0
 

Author Comment

by:hollstar
ID: 12419394
See this is the thing but, the code I want to run to stop the main page, I want to run from the iframe as I set out above ? I don't want to adjust that code... I know its harder this way lol !
0
 
LVL 2

Expert Comment

by:jonrodde
ID: 12753939
ChrisDrake:

What do you meen by: "You might also be able to tell it to load a page which you know in advance will never exist, then cancel that loading (stop) before it produces an error (eg: there's a load of IP addresses that do not exist - so trying to load one of those will cancel the current load, and then "do nothing" until the connection times out)" ?

An IP that's not valid or just "probably" not used?
Any examples?

Regards,
-jr
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

618 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