开发者

How do I load javascript code on a website by making the code think it's loading on the homepage?

Here is my problem:

I'm loading a javascript code for advertisements on my website. The only problem is that my website is full of subdomains for different topics instead of vanity urls.

i.e. example.stackoverflow.com instead of stackoverflow.com/example

The ad company thinks each subdomain is a different website, so it doesn't load the ads on any of the subdomains, only the homepage, or 开发者_Python百科other vanity urls, like .com/whatever

My question is how do I make the javascript code think it's loading on the homepage, in order for the ads to show up on the subdomains?

I thought about using iFrames, but not sure if this would work.


If you wrap your ad inclusions in a small dummy page that comes from your top-level domain, and load that page (as many times as necessary) into <iframe> tags, that should do it. Just have a minimal response document that has nothing in it other than the ad code.

Of course, if the ad code interacts with other stuff on the page, or if it expects some JavaScript libraries to be available, then you'll have to account for that. Really it depends a lot on the particular code you're using.

Presumably the ad server uses the "REFERER" value to identify the source. There's nothing you can do from JavaScript to force the browser to send anything different, though the browser user can potentially control it arbitrarily.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜