PDA

View Full Version : Lấy giá trị của popup khác domain



nobita21
03-10-2013, 10:35
Mình có trang 1 chứa text box để khi mở popup trang 2 ra rồi bấm nút thì giá trị quay về trang 1

Điều này xảy ra tốt khi cùng 1 domain, khác domain nhau thì tịt ngay

Cùng domain: http://static.giaophanthaibinh.org/test.html
Khác dommain: http://giaophanthaibinh.org/test.html

Mình đã thử cross domain nhưng ko thành công. Mong các bạn giúp

Code như sau

Trang 1:


<input type="text" id="txtImage" runat="server" width="300px" />
<input type="button" id="btnBrowsePicture" value="Mở popup" onclick="open_pop('http://static.giaophanthaibinh.org/index.html');" />
<script type="text/javascript">
function open_pop(URL) {
popupWindow = window.open(URL, 'popup', 'dependent=0,height=400px,width=750px,screenX=1,le ft=197,screenY=1,top=120,channelmode=0,dependent=0 ,directories=0,fullscreen=0,location=0,menubar=0,r esizable=1,scrollbars=1,status=0,toolbar=0', 'launcher');
if (window.focus) {
popupWindow.focus();
}
}
</script>


Trang 2:


<input type="button" value="Chèn vào Form đã mở" onclick="javascript:onSubmitOK('txtImage', 'string demo')" />

<script type="text/javascript">
function onSubmitOK(txtImgId, value) {
var oObjectID = null;
if (!window.opener.closed) {
oObjectID = window.opener.document.getElementById(txtImgId);
// oObjectID = document.getElementById('txtImgId')

if (oObjectID != null) {
oObjectID.value = value;
oObjectID.focus();
}

}
window.close();
}
</script>

Xin cảm ơn!!!

hbs315
12-11-2013, 10:01
Vì lý do bảo mật nên việc crossdomain bị hạn chế.
Mình có giải pháp như sau:
(domain1 tương đương domain1 chấm com
domain2 tương đương domain2 chấm com)
Sử dụng .htaccess để ánh xạ domain từ domain chính sang domain phụ và xử lý:
Bạn có thể dùng một sub category để ánh xạ, ví dụ: domain của bạn là domain1, bạn tạo sub cat: domain1/domain2, sau đó thêm vào htaccess


RewriteEngine on
#bỏ khoảng trắng không cần thiết
RewriteRule ^(.*)$ http: // domain2/$1 [P,L]



Giả sử bạn muốn truy cập domain2/about thì khi truy cập bạn truy cập domain1/domain2/about