<!--The element of images is the child window. I can get the javascript to work
correctly from the child window, but I need the class of the image clicke
on from the parent page to effect the child window using window.open.-->
<div class="slides">
<img class="item-1 cardone" src="images/cardone.jpg"/>
<img class="item-2 cardtwo" src="images/cardtwo.jpg"/>
<img class="item-3 cardthree" src="images/cardthree.jpg"/>
<img class="item-4 cardfour" src="images/cardfour.jpg"/>
<img class="item-5 cardfive" src="images/cardfive.jpg"/>
</div>
在點擊傳送的JavaScript從父窗口的子窗口中使用,window.open
$('.icon-search').click(newWindow); //targeting the image
function newWindow(){
var win = window.open('../carousel/index.html'); //child window
var script = document.createElement('script');
var $this = $(this).prev().attr('class'); //class of image to save for child window
//script below pertains to only child window
$("."+newSrc+"").not(this).remove('img');
$(this).insertAfter($('.slides img:nth-child(2)')).addClass('item-3');
$('.slides img:nth-child(1)').removeClass().addClass('item-1');
$('.slides img:nth-child(2)').removeClass().addClass('item-2');
script.src = 'pf-js/projects.js';
win.document.head.appendChild(script);
}
我需要的腳本調試,並在控制檯檢查時使用window.open,被轉移,沒有腳本被轉移。
試試這個:'win.document.getElementsByTagName( 「頭」)[0] .appendChild(腳本);' –
@LouysPatriceBessette腳本不工作..我的不正確的底部看win.document.head.appendChild(腳本);從您的體驗控制檯日誌應該顯示在頭部的新腳本? –