我想通過搜索特定屬性或文本的HTML src來在javascript(或jquery)中查找父div ID。搜索attr的頁面源,然後找到attr的父div
比方說,我們正在使用此代碼:
<div id="ad_creative_1" class="ad-div mastad" style="z-index: 1;">
<script>(function() {var loaded = function() {return yt && yt.www && yt.www.home && yt.www.home.ads;};window.masthead_ad_creative_iframe_1_workaround = function() {if (loaded()) {yt.www.home.ads.workaroundIE(this);}};window.masthead_ad_creative_iframe_1_onload = function() {if (!loaded()) {setTimeout(masthead_ad_creative_iframe_1_onload, 50);return;}yt.www.home.ads.workaroundLoad();};})();</script>
<iframe id="ad_creative_iframe_1" src="http://ad-g.doubleclick.net/N4061/adi/com.ythome/_default;sz=970x250;tile=1;plat=pc;dc_dedup=1;kage=18;kar=3;kbsg=HPUS130404;kcr=us;kga=1001;kgender=m;kgg=1;klg=en;kmyd=ad_creative_1;"
height="250" width="970"
scrolling="no" frameborder="0" style="z-index: 1"
onload="masthead_ad_creative_iframe_1_onload();"
onmouseover="masthead_ad_creative_iframe_1_workaround(this)"
onfocus="masthead_ad_creative_iframe_1_workaround(this)"></iframe>
<script>
(function() {
var ord = Math.floor(Math.random() * 10000000000000000);
var adIframe = document.getElementById("ad_creative_iframe_1");
adIframe.src = "http://ad-g.doubleclick.net/N4061/adi/com.ythome/_default;sz=970x250;tile=1;plat=pc;dc_dedup=1;kage=18;kar=3;kbsg=HPUS130404;kcr=us;kga=1001;kgender=m;kgg=1;klg=en;kmyd=ad_creative_1;ord=" + ord + "?";
})();
</script>
</div>
不知道父DIV是ad_creative_1,是否有可能(?如果是的話,我會怎樣吧)找出父div通過搜索源中的關鍵字?
說doubleclick.net是我們的關鍵字。
我可以搜索html頁面源代碼,找到doubleclick.net,並返回其中包含doubleclick.net的部分的父部分?
我該怎麼辦呢?
你有任何關於iframe ID的知識嗎? – Jlange 2013-04-04 19:59:32
不。我唯一的知識是doubleclick.net包含在源代碼中。 – user2246524 2013-04-04 20:02:14
請注意,使用此div可導致iframe重新加載(如移動它)會導致無效的展示次數,這可能違反了您所使用的廣告服務的TOS。 – 2013-04-04 20:02:42