Drupal 7 : How to remove viewpoint meta data ?

這問題的需求在於客戶網站不要支援 RWD (Responsive Web Resign)
由於我用 Drupal7 + Bootstrap 3.x
Bootstrap 3.x 似乎內建就把這些 RWD 給設定好了
沒辦法透過後台 admin 設定
網路上看到人家說要改掉 meta tag 最多的方式都是用 html_header_alter()
但根本沒用阿…
原因在於 viewpoint 這個 meta 不是經由 html_header_alter() 產生的

後來找到用 javascript 的方式解決了
由於我是手機才需要加入這段 js 去 override 掉原本的 meta
所以我使用 mobiledetect 這個 lib 來達到我要的效果
將 viewpoint 的 content 改成 width = 1024 (px)
至於要設定多少就看你的畫面是設計給怎樣解析度看的
code 如下:
function your_module_init() {
  // call Mobile_Detect lib
  require_once libraries_get_path('Mobile_Detect').'/Mobile_Detect.php';
  $detect = new Mobile_Detect;
  if ($detect->isMobile()) {
    drupal_add_js("
    viewport = document.querySelector(\"meta[name=viewport]\");
    viewport.setAttribute('content', 'width=1024');
    ", 'inline');
  }
}

Reference
Can I change the viewport meta tag in mobile safari on the fly?

Comments

Popular posts from this blog

CentOS7 如何新增/移除 Rich Rule for firewalld

mac 安裝 mtr

Howto use Postman test Cors