-1

The onload="" method in html stays for "Fires after the page is finished loading" I need a method that loads the < script > part directly at FIRST while the page is loading.

<!doctype html>
<html>
<head>
<!--Adobe Edge Runtime-->
<script>
var custHtmlRoot="hin-aktuell/Assets/"; 
var script = document.createElement('script'); 
script.type= "text/javascript";
script.src = custHtmlRoot+"edge_includes/edge.6.0.0.min.js";
var head = document.getElementsByTagName('head')[0], done=false;
script.onload = script.onreadystatechange = function(){
    if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
        done=true;
        var opts ={
scaleToFit: "width",
centerStage: "none",
minW: "0px",
maxW: "undefined",
width: "1366px",
height: "768px"
};
        opts.htmlRoot =custHtmlRoot;
        AdobeEdge.loadComposition('hin-aktuell', 'EDGE-2489594', opts,
        {"style":{"${symbolSelector}":{"isStage":"true","rect":["undefined","undefined","1366px","768px"],"fill":["rgba(255,255,255,1)"]}},"dom":{}}, {"dom":{}});      
        script.onload = script.onreadystatechange = null;
        head.removeChild(script);
    }
};
head.appendChild(script);
</script>
<style>
    .edgeLoad-EDGE-2489594 { visibility:hidden; }
</style>
<!--Adobe Edge Runtime End-->

<script> alert(1); </script>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<title>NC | Allgemeines</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="feed.css">
</head>

here is the body part

<body> 
    <div id="EdgeStage">
      <div id="Stage" class="EDGE-2489594"></div>
    </div>
    <div id="feeds">            
        <?php
            $html = "";                    
            $url = "http://www.yoursite.com";            
            $xml = simplexml_load_file($url);
                for($i = 0; $i < 1; $i++){
                    $description = $xml->channel->item[$i]->description;
                    preg_match("/<img[^>]+\>/i", $description, $matches);
                    if (isset($matches[0])) {
                        $html .= $matches[0];
                    } else {                                
                        echo "No img";
                    }                            
                }
                echo $html;
        ?>
    <div/>
</body>

now thats the hole file...

Bob
  • 83
  • 1
  • 1
  • 7
  • Have you consider load in ajax?, then on sucess fires the second function – fsalazar_sch Aug 05 '15 at 00:43
  • can't follow you... can you explain it please... i'm not that good in programming – Bob Aug 05 '15 at 00:57
  • What does "code from edge animate" have to do with your question? Except that if you have two things setting `onload`, only one will succeed (unless you chain them). But that doesn't matter since you're not using `onload`, right? – Amadan Aug 05 '15 at 01:14
  • i imported an edge animate animation inside my html... i want to have this animation come first... maybe the script.onload = script.onreadystatechange = function(){} part says that the animation should start after the page has completely loaded... – Bob Aug 05 '15 at 01:26
  • and with this part -> if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) i think it also stops the animation to be the at first loaded on the page??? – Bob Aug 05 '15 at 01:26

1 Answers1

1

A page executes in order. If you place your script as the very first thing in <head>, it will execute before anything else. Note that due to its timing, the page's <body> will not exist yet (nor, in fact, anything else in <head>).

There is no event for when page starts loading, since there can't possibly be any code to handle such an event at that time. At least your <script> element needs to be loaded first.

Amadan
  • 191,408
  • 23
  • 240
  • 301
  • i tried it and took it to the first thing on top of the part... but it does not work... is there anything else to take care of? maybe i have a problem in the code with the onload like in the description line 8? – Bob Aug 05 '15 at 01:13
  • 1
    "does not work" is a useless description. What happened? Was there an error in the console? Did you place it correctly? `....` should always, always, execute first, no matter what. (Well, not if you have JavaScript switched off, obviously.) – Amadan Aug 05 '15 at 01:15
  • worked fine and show me the alert... but don't show me the edge animation part – Bob Aug 05 '15 at 01:28
  • You asked about running `test()`; `test()` will run. But I said that when the document starts loading, there is no document yet: nothing to animate (no content), and nothing to animate with (no adobe edge). You should clarify, a *lot*, what exactly you are trying to do. What is the structure of your document, what does `test()` try to do, and when do you want it done? – Amadan Aug 05 '15 at 01:35
  • ok let me try to explain it... so in the html is a picture and an animation (made in edge animate)... the side is loading the picture first and show me than the animation... but i want it the other way around.. first animation and load after the animation the picture... thx amadan for your efforts... – Bob Aug 05 '15 at 01:44
  • If I understood, you want to show the animation, then when it finishes, show your pictures? Load pictures via Ajax hidden, then show when the animation finishes ([this question](http://stackoverflow.com/questions/12357216/adobe-edge-add-oncomplete-handler-when-animation-finishes) seems to show how). – Amadan Aug 05 '15 at 03:27