我在頁面上使用JQuery UI對話框,並在其中顯示另一個頁面(page2.htm)的內容。我的代碼如下:獲取JQuery對話框的子窗口位置
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Test</title>
<script src="Scripts/jquery-1.6.4.js"></script>
<script src="Scripts/jquery-ui-1.11.4.js"></script>
<script>
$(document).ready(function() {
$(".hlk1").click(function() {
var linkId = $(this).attr("linkID");
// initialize dialog
var dlg = $("#dialog").dialog({
autoOpen: false,
modal: true,
draggable: false,
resizable: false,
position: { my: "center", at: "center", of: window },
height: 380,
width: 530,
dialogClass: 'ui-dialog-osx',
buttons: {
"Done": function() {
$(this).dialog("close");
}
}
});
// load content and open dialog
dlg.load('page2.html?id=' + linkId).dialog('open');
});
});
</script>
</head>
<body>
<a href="#" class="hlk1" linkid="305">Click here</a>
<br/>
<a href="#" class="hlk1" linkid="890">Click here</a>
<br/>
<div id="dialog"></div>
</body>
</html>
在我page2.html我想從URL抓取的查詢字符串到該網頁上使用,但是當我試圖讓位置,我得到父頁面的URL使用
this.location
我的問題是我如何獲得在div中顯示的page2.html的URL?
這裏是我的page2.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Page 2</title>
<script src="Scripts/jquery-1.6.4.js"></script>
<script>
$(document).ready(function() {
alert(this.location);
});
</script>
</head>
<body onload="this.focus()">
<div>
<h1>Page 2</h1>
<div style="margin-top: 10px;">
<input type="text" id="PostId"/>
</div>
</div>
</body>
</html>
當頁面2的內容加載到對話框中後,您是否看到警告? – Yass
是的,我看到了警報,它是父頁面的URL – ElenaDBA