Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
152
rated 0 times [  158] [ 6]  / answers: 1 / hits: 19437  / 11 Years ago, wed, july 24, 2013, 12:00:00

I'm using window.location.href to load a page and now I have switched over to window.onload() function, but the page does not load some contents.



window.location.href = $(this).val(); is the code I'm using.



How can I write it using window.onload() function?


More From » php

 Answers
50

window.onload is a property to which you can assign a function that will run when the page has finished loading. It doesn't have a function assigned to it by default, so you can't call it unless you first assign a function to it. It has nothing to do with causing the browser to go to a different URL.



Assigning an onload function directly has also been superseded by addEventListener.



You could assign a function to it that would set location.href to a new value



// Don't do this
function redirect() {
location.href = http://example.com;
}
addEventListener('load', redirect);


… but if you are doing that as soon as the page loads then you should be using an HTTP redirect instead.


[#76788] Monday, July 22, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lamarmaximiliand

Total Points: 388
Total Questions: 104
Total Answers: 104

Location: Oman
Member since Fri, Dec 23, 2022
1 Year ago
;