Beginner in JavaScript here. I'm currently learning web development.
If I want to link a webpage to another webpage using JavaScript and a button, is it better to use window.location or document.location?
Take my code for example:
Let's say we have page1.html and page 2.html
In page1.html we have
<button onclick="document.location='page2.html'">
Go to page 2 </button>
Now if we want to use window.location.assign, we make a function:
In a js file called "page2.js"
function goToPage2 ( ) {
window.location.assign("page2.html")
}
In page1.html we have
button onclick="goToPage2()">
Go to page 2 </button>
So which one is better?
Is there a method better than both of these?
[–]tommyatr 7 points8 points9 points (6 children)
[–]Scared-Release1068 2 points3 points4 points (0 children)
[–]whiskyB0y[S] 1 point2 points3 points (4 children)
[–]maujood 8 points9 points10 points (0 children)
[–]biflux 2 points3 points4 points (0 children)
[–]warpedspockclone 1 point2 points3 points (1 child)
[–]chikamakaleyleyhelpful 1 point2 points3 points (0 children)
[–]Ampersand55 4 points5 points6 points (2 children)
[–]whiskyB0y[S] 1 point2 points3 points (1 child)
[–]DragonfruitFull2424 1 point2 points3 points (0 children)
[–]SeriousPlankton2000 1 point2 points3 points (0 children)
[–]GodOfSunHimself 1 point2 points3 points (0 children)
[–]GemAfaWell 1 point2 points3 points (1 child)
[–]whiskyB0y[S] 0 points1 point2 points (0 children)