Rising nationalism throughout the 19th century led to a 1905 referendum granting Norway independence .