Thursday, May 20, 2010

Creating alert box to take user to new page with js?

Here is the code that I have for the alert box:





%26lt;script type="text/javascript"%26gt;


onload=function(){alert("Please Take Our Customer Service Survey")}


%26lt;/script%26gt;





Is works fine, however, what I need is to give the user a option and take them to a new page when they click yes.

Creating alert box to take user to new page with js?
Don't you just hate it when there's no native widget that does what you want?! Makes you want to go out and learn a programming language or something!





%26lt;html%26gt;


%26lt;head%26gt;


%26lt;style%26gt;


#survey {


background-color: #EEE;


border: 4px double red;


display: none;


height: 90px;


left: 200px;


position: absolute;


text-align: center;


top: 200px;


width: 350px;


}


%26lt;/style%26gt;


%26lt;script type="text/javascript"%26gt;


function openSurvey() {


// display do-survey request to visitor


var d = document;


var s = d.getElementById('survey');


s.style.display = 'block';


}





function closeSurvey() {


// hide do-survey request from visitor


var d = document;


var s = d.getElementById('survey');


s.style.display = 'none';


}





function doSurvey() {


closeSurvey();


// load survey input form page


location = 'your_survey_page.html';


}





// on entry, request that visitor takes survey


window.onload = openSurvey;


%26lt;/script%26gt;


%26lt;/head%26gt;


%26lt;body%26gt;


%26lt;div id="survey"%26gt;


%26lt;p%26gt;Please Take Our Customer Service Survey.%26lt;/p%26gt;


%26lt;form%26gt;


%26lt;input type="button" value="Yes" onclick="doSurvey();" /%26gt;


%26lt;input type="button" value="No" onclick="closeSurvey();" /%26gt;


%26lt;/form%26gt;


%26lt;/div%26gt;


%26lt;p%26gt;page content goes here%26lt;/p%26gt;


%26lt;/body%26gt;


%26lt;/html%26gt;
Reply:The confirm() function will return true when the user clicks OK, and false when they click Cancel. That's as close as you can get with Javascript.


No comments:

Post a Comment