0

I was browsing to a webste with Chrome, I turned on the Inspect ( Ctrl + Shift + I ) and then I was trying to trace what javascript chart library it's using.

But I find out when I click the "Toggle Device Tollar" and switch to the mobile mode (vice versa) or press rorate when on mobile mode .

The website knows those behaviors and reload whole page. Not just responsive CSS but actually re-request the whole page such as the behavior of presssing F5 on the web page.

I was trying to find the javascript event to know how it detect these behaviors(toggle on device and rorate) and do reload, but I couldn't find it via break point in the Chrome dugger.

Any ideas how this website makes it?

before pressing "toggle device toolbar" enter image description here

after pressing "toggle device toolbar" enter image description here

JasonHsieh
  • 553
  • 1
  • 6
  • 20

2 Answers2

2

You are looking for this:

window.addEventListener("orientationchange", function() {
    alert("the orientation of the device is now " + screen.orientation.angle);
});

Refer to the documentation.

iiirxs
  • 4,493
  • 2
  • 20
  • 35
2

The orientationchange event is fired when the orientation of the device has changed. This link may be helpful https://developer.mozilla.org/en-US/docs/Web/Events/orientationchange

// Note that "orientationchange" and screen.orientation are unpre fixed in the following
// code although this API is still vendor-prefixed browsers implementing it.

    window.addEventListener("orientationchange", function() {
        alert("the orientation of the device is now " + screen.orientation.angle);
    });
  • 3
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/20485671) – eisbehr Aug 03 '18 at 07:47
  • 1
    Thanks @eisbehr for your valuable suggestion. I will include essential parts of the answer now onward. –  Aug 03 '18 at 08:29