html - My Javascript function is influenced by another JS function already defined -
i have html/css/js page css , js functions (not created myself) defined within <head> tag. page displaying title @ beginning , beneath there 4 tabs defined css style working dynamically using js. wanted add own js function, should loading onload:
<script type="text/javascript"> function replacesrc() { document.getelementbyid("ytplayer").src = "blablabla"; } window.onload = replacesrc; </script> however, when running page, content produced css/js disappears (just title of page remains).
so questions are:
- can problem there 1 js function defined loading
onload? - if so, how handle it?
i have tried put function declaration different places within html, removing tag , putting tag, still not work.
when (or somebody's else) use window.onload = somefunction, remove precedently attached load event handler.
you should use addeventlistener :
window.addeventlistener('load', replacesrc); if want compatible old ie browsers, use
if (window.addeventlistener){ window.addeventlistener('load', replacesrc, false); } else if (window.attachevent) { window.attachevent('onload', replacesrc); } edit : comment, seems you're trying change src of iframe served server origin. can't due same origin policy. see example related question : change src iframe cross-domain
Comments
Post a Comment