/    Sign up×
Community /Pin to ProfileBookmark

JS object error

Not sure what I’m doing wrong. I am just attempting to put some info into some javascript variables, but I must be misunderstanding how to have multiple variables in a function.

<script language=”JavaScript”>

var stuff1 = “Alert Message here!”;
var stuff2 = document.getElementById(“styled_popup”).style.display=”block”;

window.onbeforeunload = confirmExit;
function confirmExit()
{
return [stuff1,stuff2];
}
</script>

Am I putting the sytax correctly? Because I get no return when I leave the page.

However, if I put the data (from the variables) directly into the return[] portion, then it works.

Any thoughts?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Killzone_KidJan 13.2008 — Not sure what I'm doing wrong. I am just attempting to put some info into some javascript variables, but I must be misunderstanding how to have multiple variables in a function.




<script language="JavaScript">

var stuff1 = "Alert Message here!";

var stuff2 = document.getElementById("styled_popup").style.display="block";


window.onbeforeunload = confirmExit;

function confirmExit()

{

return [stuff1,stuff2];

}

</script>


Am I putting the sytax correctly? Because I get no return when I leave the page.

However, if I put the data (from the variables) directly into the return[] portion, then it works.

Any thoughts?[/QUOTE]


Obviously. Your stuff2 variable equals to "block" after the assignment. What you need is to make it a function.

var stuff2 = function () {document.getElementById("styled_popup").style.display="block";};
×

Success!

Help @netfrugal spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...