これは変更が必要なようです
$('index.html#target').load('user.php');
に
$('#target').load('user.php');
編集: わかりました、いくつかの非常に基本的なマークアップを使用して、うまくいけば便利なコードを追加します。これはあなたのコードに固有のものではありませんが、概念は有用であり、2、3 の html ページだけでテスト可能であり、派手なものは何もありません。
ここで説明するのは、あるページから、別のページからスクリプトを呼び出す方法です。メイン ページと呼ぶ 1 つのページ/ウィンドウと、子ページと呼ばれる別のページ/ウィンドウを作成します。これはどれも非常に凝ったマークアップではありません。
それらは、いくつかの非常に基本的なスクリプト呼び出しを使用して対話し、相互に情報をやり取りします。最初にそれぞれのマークアップを示し、次にそれぞれのスクリプトを示します。各ページのヘッダーには jQuery がリンクされています。
ここでの私の主なポイントは、各ページへの参照を取得する限り、これの修正バージョンを使用して、別のページからインスタンス化されたスクリプト/アクションを使用して何かを実行するように 1 つのページに指示できるということです。私の例では、この参照用に window open と window.opener を使用しています。
メイン ページのマークアップ: ページは「TestCallbackmain.html」です。
<body>
<div class='pagetop'>
Test Callback Main
</div>
<div class='pageDetailContainer'>
<div class='pageDetail'>
Move on folks, nothing to see here
<div id='detailContent'>
</div>
<button id='closeChildy'>
Close Childy Window</button>
<button id='openChildy'>
Open Childy Window</button>
<div id='childSees'>
me empty</div>
</div>
</div>
</body>
子ページのマークアップ: これは「TestCallBack.html」と呼ばれます
<body>
<div class='pagetop'>
Test Callback Child
</div>
<div class='pageDetailContainer'>
<div class='pageDetail'>
<div id="achildy">
HereIBe
<div id="inchildy">
I am childy text
</div>
</div>
<button id='pleaseKillMe'>
Have Parent Close Me</button>
<div id='textHolder'>
</div>
<div id='callbackTextHold'>
</div>
</div>
</div>
Howdy
</body>
メインページのスクリプト:
function logNewWindow(newWindow, JQnewWindowDoc) {
var mychildText = JQnewWindowDoc.text(); //all the child doc text
var innerChildText = $("#inchildy", JQnewWindowDoc).text(); // one element text
var gotback = newWindow.childCallBack("CHILD TEXT:" + mychildText + " INNER:" + innerChildText);
$('#callbackTextHold').text("GOT:" + gotback); //child sent me this text from childCallBack
};
var AWindow;
function openChild() {
AWindow = window.open("TestCallBack.html");
};
$(document).ready(function() {
$('#detailContent').text('Loaded JQ');
$('#closeChildy').click(function() {
AWindow.close();
});
$('#openChildy').click(function(e) {
openChild();
e.stopImmediatePropagation();
});
});
子ページのスクリプト:
var ct;
function childCallBack(passstuff) {
$('#textHolder').html('ct:"' + ct + '"<br /> CHILD GOT:(' + passstuff + ")");
return ct;
};
$(document).ready(function() {
ct = $("#achildy").text();
window.opener.logNewWindow(window, $(document));
$('#childSees', window.opener.document).text('You been Had by child');
$('#pleaseKillMe').click(function() {
$('#closeChildy', window.opener.document).click();
});
});