admin管理员组

文章数量:1293703

I have a couple of ad networks that have been able to integrate a passback URL (requested when a paid ad impression is not available) but one ad network can only accept a passback script tag, which I don't have.

The passback script needs to load the contents of a URL (a 728x90 image or flash banner) into itself (it also needs to execute the Javascript that it loads). Can anyone help me construct a passback script tag?

I tried this:

<SCRIPT language="Javascript">

// loads within itself, in the 728x90 banner space

document.write("<SCR"+"IPT language=\'Javascript\' src=\'.php\'></SCR"+"IPT>");

</SCRIPT>

But got script errors. Any ideas?

I have a couple of ad networks that have been able to integrate a passback URL (requested when a paid ad impression is not available) but one ad network can only accept a passback script tag, which I don't have.

The passback script needs to load the contents of a URL (a 728x90 image or flash banner) into itself (it also needs to execute the Javascript that it loads). Can anyone help me construct a passback script tag?

I tried this:

<SCRIPT language="Javascript">

// loads within itself, in the 728x90 banner space

document.write("<SCR"+"IPT language=\'Javascript\' src=\'http://www.mydomain./passback.php\'></SCR"+"IPT>");

</SCRIPT>

But got script errors. Any ideas?

Share Improve this question edited Nov 13, 2011 at 14:07 Some Guy 16.2k10 gold badges60 silver badges68 bronze badges asked Nov 9, 2011 at 15:23 TomTom 1,0452 gold badges14 silver badges23 bronze badges 4
  • 1 @Tom How does the passback.js file look like? – Rob W Commented Nov 13, 2011 at 14:50
  • What errors did you get? – J. K. Commented Nov 13, 2011 at 18:47
  • Your code (the part you've shown) is fine. It's the script pointed in src attribute that causes the problems - care to share it? Also, following Jan question - what script errors are you getting? – WTK Commented Nov 17, 2011 at 8:55
  • does passback.php have the correct MIME type? – user69820 Commented Nov 18, 2011 at 13:28
Add a ment  | 

3 Answers 3

Reset to default 6 +175

Just an idea. What does it give if you try this ?

<SCRIPT language="JavaScript" type="text/javascript">

var script = document.createElement("script");
script.type = "text/javascript";  // This is for HTML 4.01 validation
script.src = "http://www.mydomain./passback.php";
document.getElementsByTagName("head")[0].appendChild(script);

</SCRIPT>

The script already provided is close to the one I always use for this:

var js = document.createElement("script");
js.type = "text/javascript";
js.src = "//www.mydomain./passback.php";
document.getElementsByTagName('head')[0].appendChild(js);

The only thing that is different is that the URL scheme is not specified therefore if you are running on an http server then the http url will be called and if you run on https then https will be called - mixing them would be reason that you scripts may not load.

With your script error I would suggest using Chrome and the developer tools - this would allow you to see exactly which line is giving you that error.

The following function loads another document into document body. The URL of the new document should be in the same domain which is http://www.mydomain./ in your case.

You need to save the following script as a .js file and put it where the ad should be placed.

function load(url) {
    var req = null;

    if (window.XMLHttpRequest) {
        req = new window.XMLHttpRequest();
    }
    else if (window.ActiveXObject) { //fallback
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) { }
        }
    }

    if (req) {
        req.open("GET", url, false);
        req.send(null);
        return req.responseText;
    }
}

document.write(load("http://www.mydomain./passback.php"));

本文标签: javascriptHow do I create a passback tag from a URLStack Overflow