簡體   English   中英

僅在某些屏幕分辨率下包含php文件

[英]include php file only at certain screen resolutions

我在響應式設計方面遇到了問題。 我找到的一個解決方案是,如果窗口尺寸不夠大,根本不加載它們。 所以我想我會用廣告代碼,容器等創建一個單獨的php文件......而不是將它包含在頁面上。 但是,如果窗口寬度為720px或更高,我不知道如何只包含此文件,否則不包含此文件。 也許,javascript可以用某種方式,不知道它將如何適用於所有的dom和PHP包括雖然。

您可以嘗試以下方式:

<script language=javascript>
    if (screen.width >= 720 ) 
         $('#place_holder_div').load('file_from_server.php');
</script>

這里#place_holder_div是你的html文件中的div。 語法是Jquery但是如果你願意,你當然可以使用普通的javascript。 代碼查看屏幕寬度,如果大於720像素,則將php文件file_from_server.php (包含您的廣告)加載到占位符div中。

了解客戶端窗口或屏幕大小的唯一方法是使用JavaScript。

window.innerHeight; // Available height of the browser for the document
window.innerWidth; // Available width of the browser for the document
window.outerHeight; // Browser height
window.outerWidth; // Browser width
window.screen.height; // Screen height
window.screen.width; // Screen width

檢查完這些后,您可以對相關文件執行HTTP請求。 然而,它可能不是最佳解決方案,因為用戶實際上可以在任何給定時間改變上述任何尺寸。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM