Web Analytics Made Easy -
StatCounter Include JS in iframe with DOM - CodingForum

Announcement

Collapse
No announcement yet.

Include JS in iframe with DOM

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Include JS in iframe with DOM

    Hi

    I have HTML file:

    PHP Code:
    <iframe src="http://domain.com/text.html"></iframe
    Javascript code:

    PHP Code:
    function js_include(sFileName){
    var 
    objHead document.getElementsByTagName('head');
    var 
    objScript document.createElement('script');
    objScript.type 'text/javascript';
    objScript.src sFileName;
    objHead[0].appendChild(objScript);

    I need include js in iframe. Example:

    PHP Code:
    js_include('text.js'
    Content of text.js:

    PHP Code:
    document.write("Text in iframe"); 
    When iframe will have: Text in iframe

    I get element of iframe with code:

    PHP Code:
    var elements;
    if(
    document.getElementsByTagName) {
        
    elements document.body.getElementsByTagName("IFRAME");
    } else if (
    document.body.all) {
        
    elements document.body.all.tags("IFRAME");
    } else {
        
    elements = Array();
    }
    for(var 
    0elements.lengthi++) {
        if(
    elements[i].src.indexOf('text.html') > -1) {
            
    // Please help me here, how to include js in iframe which src have text.html. Thanks
        
    }


  • #2
    Help me please!

    Comment

    Working...
    X