hello i need some function going to run after a link before another page.
for example.
this is main.html
<div>
<a href="another.html" onclick="linkPopup()" target="_blank" title="popup"></a>
</div>
and when click tag.
another.html loaded and open popup inside in function exist already in another.html
another.html open popup!
like this.
CodePudding user response:
simple, Change your html like this way
<a href="#" onclick="linkPopup()" title="popup"> Another Page </a>
Then define you function like this way
function linkPopup() {
// do your function task here
alert("Alert");
// go to the another page
window.location.href = "another.html";
}
CodePudding user response:
i think you need to call function before goes to another.html , to achieve this , very simple is
remove link from anchor and location.href in function
function linkPopup()
{
//some code here and last line is below,
location.href = 'another.html';
}
CodePudding user response:
Use localStorage for this functionality. https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
Page current.html
<a href="javascript:;" onclick="linkPopup()" title="popup"> Another Page </a>
<script>
function linkPopup(){
localStorage.setItem('popup',true)
window.location.href = "another.html";
}
</script>
Page another.html
<script>
document.addEventListener('DOMContentReady',function(){
if(localStorage.getItem('popup')==true){
// Script for open the popup
}
})
</script>