By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,743 Members | 1,122 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,743 IT Pros & Developers. It's quick & easy.

setinterval breaking my script

P: 1
hi. a javascript newbie here in dire need of help.
for the past 3 days i've been trying to get a script using setinterval to work but a part of the code, that executes after setinterval hits a certain amount of time and clearinterval is invoked, opens on a new page instead of displaying in the designated div.

i've tried 2 ways of displaying the code
1. getelementbyid('designatedarea').innerhtml
and
2. var x document.createElement("script");
x.setAttribute("type","text/javascript");
x.setAttribute("src","blah.phporjs");
x.setAttribute("language","JavaScript");
document.getElementById("designateddiv").appendChi ld(x);

now if the code that needed to be executed after the setinterval is completed is regular html or text everything is dandy

the problem is the code i need to execute in the innerhtml or appendchild segment is another javascript (specifically a javascript code to display flash files)

with innerhtml and appendchild after the setinterval completes, the flash javascript opens in a new page by itself instead of in the designated (div) area.

now i understand that document.write can't be executed after the page has loaded without overwriting the entire page but if i needed to run say a javascript ad code that i would have no control over after setinterval, is there anyway to do so?
the only solution i have is to use iframes but it would be an improper and restricting solution.
any help would be greatly appreciated.

[edit] that's probably a poor title blaming little ole setinterval, who's just doing his job, for my ineptitude, but i just wanted to show that the problem is centered around setinterval.

here is the flash script i want to execute after clearinterval
the function part(tried implementing it externally and internally)

Expand|Select|Wrap|Line Numbers
  1. //v1.0
  2. //Copyright 2006 Adobe Systems, Inc. All rights reserved.
  3. function AC_AddExtension(src, ext)
  4. {
  5.   if (src.indexOf('?') != -1)
  6.     return src.replace(/\?/, ext+'?'); 
  7.   else
  8.     return src + ext;
  9. }
  10.  
  11. function AC_Generateobj(objAttrs, params, embedAttrs) 
  12.   var str = '<object ';
  13.   for (var i in objAttrs)
  14.     str += i + '="' + objAttrs[i] + '" ';
  15.   str += '>';
  16.   for (var i in params)
  17.     str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  18.   str += '<embed ';
  19.   for (var i in embedAttrs)
  20.     str += i + '="' + embedAttrs[i] + '" ';
  21.   str += ' ></embed></object>';
  22.  
  23.   document.write(str);
  24. }
  25.  
  26. function AC_FL_RunContent(){
  27.   var ret = 
  28.     AC_GetArgs
  29.     (  arguments, "", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
  30.      , "application/x-shockwave-flash"
  31.     );
  32.   AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
  33. }
  34.  
  35.  
  36.  
  37. function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  38.   var ret = new Object();
  39.   ret.embedAttrs = new Object();
  40.   ret.params = new Object();
  41.   ret.objAttrs = new Object();
  42.   for (var i=0; i < args.length; i=i+2){
  43.     var currArg = args[i].toLowerCase();    
  44.  
  45.     switch (currArg){    
  46.       case "classid":
  47.         break;
  48.       case "pluginspage":
  49.         ret.embedAttrs[args[i]] = args[i+1];
  50.         break;
  51.       case "src":
  52.       case "movie":    
  53.         args[i+1] = AC_AddExtension(args[i+1], ext);
  54.         ret.embedAttrs["src"] = args[i+1];
  55.         ret.params[srcParamName] = args[i+1];
  56.         break;
  57.       case "onafterupdate":
  58.       case "onbeforeupdate":
  59.       case "onblur":
  60.       case "oncellchange":
  61.       case "onclick":
  62.       case "ondblClick":
  63.       case "ondrag":
  64.       case "ondragend":
  65.       case "ondragenter":
  66.       case "ondragleave":
  67.       case "ondragover":
  68.       case "ondrop":
  69.       case "onfinish":
  70.       case "onfocus":
  71.       case "onhelp":
  72.       case "onmousedown":
  73.       case "onmouseup":
  74.       case "onmouseover":
  75.       case "onmousemove":
  76.       case "onmouseout":
  77.       case "onkeypress":
  78.       case "onkeydown":
  79.       case "onkeyup":
  80.       case "onload":
  81.       case "onlosecapture":
  82.       case "onpropertychange":
  83.       case "onreadystatechange":
  84.       case "onrowsdelete":
  85.       case "onrowenter":
  86.       case "onrowexit":
  87.       case "onrowsinserted":
  88.       case "onstart":
  89.       case "onscroll":
  90.       case "onbeforeeditfocus":
  91.       case "onactivate":
  92.       case "onbeforedeactivate":
  93.       case "ondeactivate":
  94.       case "type":
  95.       case "codebase":
  96.         ret.objAttrs[args[i]] = args[i+1];
  97.         break;
  98.       case "width":
  99.       case "height":
  100.       case "align":
  101.       case "vspace": 
  102.       case "hspace":
  103.       case "class":
  104.       case "title":
  105.       case "accesskey":
  106.       case "name":
  107.       case "id":
  108.       case "tabindex":
  109.         ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
  110.         break;
  111.       default:
  112.         ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
  113.     }
  114.   }
  115.   ret.objAttrs["classid"] = classid;
  116.   if (mimeType) ret.embedAttrs["type"] = mimeType;
  117.   return ret;
  118. }
  119.  
and the function to run after clearinterval is AC_FL_RunContent();
Sep 14 '08 #1
Share this Question
Share on Google+
1 Reply


Atli
Expert 5K+
P: 5,058
Hi.

You can add a new <script> elements to the header like so:
Expand|Select|Wrap|Line Numbers
  1. newScript = document.createElement("script");
  2. newScript.type = "text/javascript";
  3. newScript.src = "myScript.js";
  4. document.getElementsByTagName("head")[0].appendChild(newScript);
  5.  
But... why do you use all that JavaScript to run a flash movie?
Couldn't you just use something like:
Expand|Select|Wrap|Line Numbers
  1. <object 
  2.     type="application/x-shockwave-flash" 
  3.     data="mymovie.swf" 
  4.     width="550" height="400"> 
  5.     <param name="movie" value="mymovie.swf" /> 
  6.     <param name="quality" value="high"/> 
  7.     <p>You don't have flash?!</p> 
  8. </object>
  9.  
and either add that in the innerHTML of you target element or add the element dynamically?
Sep 15 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.