How to get node id on hook_page_build(&$page)
Still comes through the URL indirectly, but this is the easiest way to get it: menu_get_object.

&lt;?
if ($node = menu_get_object()) {
 $nid = $node-&gt;nid;
}
?&gt;


Note that if there is a node, it was already loaded by the menu system anyway and this is loaded from the static cache.

Refer this discussion for more detail.