Solved

STOP Other pages loading once main is loaded ?

Posted on 2004-10-23
2,211 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
Question by:hollstar
    17 Comments
     
    LVL 36

    Expert Comment

    by:Zyloch
    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
    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
    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
     
    LVL 31

    Expert Comment

    by:GwynforWeb
    .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
    Ah, thanks for that, I've never had to use window.stop heh
    0
     
    LVL 31

    Expert Comment

    by:GwynforWeb
     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
    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
    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
    Go(0) Call ?

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

    Expert Comment

    by:GwynforWeb
    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
    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
    I forget exactly - history.go(0) or window.go(0) or something.  Check the MSDN site
    0
     
    LVL 2

    Expert Comment

    by:ChrisDrake
    0
     

    Author Comment

    by:hollstar
    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:
    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
    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
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    Web Page screen capture 3 30
    Javascript Error or bug? 9 23
    upload zip file from Ionic to NodeJS 5 26
    Create a triangle 9 24
    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved." Ralph Waldo Emerson Introduction: One of the wonderful things about the web is that it makes it s…
    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    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…

    884 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

    21 Experts available now in Live!

    Get 1:1 Help Now