Eναλακτικες λυσεις για το window.open ??

Κώδικας, πληροφορίες, ερωτήσεις και απαντήσεις σχετικές με την JavaScript.

Συντονιστές: WebDev Moderators, Super-Moderators

Απάντηση
Sotos
Δημοσιεύσεις: 7
Εγγραφή: 10 Απρ 2007 22:14

Eναλακτικες λυσεις για το window.open ??

Δημοσίευση από Sotos » 13 Απρ 2007 00:29

Αν μπορουσε καποιος να μου πει πως γινεται στον κωδικα παρακατω να μην ανοιγει σε καινουργιο παραθυρο και να ανοιγει στην ιδια σελιδα η' καπως αλιως.Θα με βοηθουσε παρα πολυ!

Κώδικας: Επιλογή όλων

results=window.open("","","height=,width=,scrollbars=yes") 

results.document.open(); 

results.document.write &#40;"<html>" + 

"<head><title>Answers</title>"+ 

"<body bgcolor=blue text=white>"+ 

"<hr>"+"<BR>" + 

"Number 1 is &#58; "+AA&#91;1&#93; +"<br>"+ 

"Number 2 is&#58; "+AA&#91;2&#93; +"<br>"+ 

"Number 3 is&#58; "+AA&#91;3&#93; + "<br>"+ 

"Number 4 is &#58; "+AA&#91;4&#93; +"<br>"+ 

"<br><br>"+ 

AA&#91;0&#93; + ", you got "+z+" correct out of "+ numberQuestions +"<br><br>" + "Your score is "+ Math.round&#40;&#40;z/ numberQuestions&#41; * 100&#41;+" %" 

+"<br><br></body></html>"&#41;; 

results.document.close&#40;&#41;; 

&#125; 


</script>

Άβαταρ μέλους
ALKIVIADES
Honorary Member
Δημοσιεύσεις: 1322
Εγγραφή: 07 Απρ 2005 03:39

Eναλακτικες λυσεις για το window.open ??

Δημοσίευση από ALKIVIADES » 13 Απρ 2007 01:57

'Αν το θές στο ίδιο παράθυρο απλά δεν πρέπει να ανοίξεις ποτέ ένα όπως κάνεις με το μέρος του script που ανέφερες παραπάνω , βγάλε τις 3 γραμμές με τις οποίες ανοίγει το νέο παράθυρο και χρη/σε μόνο το document.write κανονικά..

Κώδικας: Επιλογή όλων

<html>

<head>
<title>Test Your Knowledge</title>
</head>

<body bgcolor="#f5f5f5">

<h1>Test Your Knowledge About M&amp;M's</h1>

<script language="JavaScript">



/*Declare the array.*/

numberQuestions = 4

var AA=new Array&#40;numberQuestions + 1&#41;;

/*A nested for loop.

The outer loop cycles through each question asked.

The inner loop checks the value of each answer. Since we have three responses to each quiz, the middle parameter is 3. Change this number to correspond to the number of responses per question in your quiz.*/

function first&#40; &#41; &#123;

for &#40;var w=1; w <= numberQuestions; w++&#41; &#123;

for&#40;var n=0; n <=3; n++&#41;&#123;

/*This if statement checks to see if that particular response was selected. If it was, then the value of the response is put in the array AA. Notice also that I am accessing the forms through the forms array. Using the forms array enables me to check through all the questions using a loop, instead of accessing each form individually.*/

if &#40;document.forms&#91;w&#93;.elements&#91;n&#93;.checked&#41;&#123;

AA&#91;w&#93; = document.forms&#91;w&#93;.elements&#91;n&#93;.value;

&#125;

&#125;

&#125;

/*This places the name of the person taking the quiz into the 0th position of the array. Remember that arrays begin at position 0. This will be the persons name.*/

AA&#91;0&#93; = document.id.input1.value

var z=0;

/*This little for loop cycles through the responses that are stored in the array AA. If the answer is correct, and you need to type the word correct, no spaces, capitalization or any other variation, then we add 1 to the value of z. This will enable us to determine what percentage of questions the student got correct.*/

for &#40;var n=1; n<= numberQuestions; n++&#41; &#123;

if &#40;AA&#91;n&#93; == "correct"&#41; &#123;z+=1&#125;;

&#125;

/*Opens a new window to display the choices selected by the user and the percentage correct. If you asked more than 4 questions, you will need to copy/paste the line highlighted in blue and change the number to the corresponding question number.  For example, if there is a fifth question, add a line "Number 5 is &#58; "+AA&#91;5&#93; +"<br>"+  to the code below.*/






document.write &#40;"<html>" +

"<head><title>Answers</title>"+

"<body bgcolor=blue text=white>"+

"<hr>"+"<BR>" +

"Number 1 is &#58; "+AA&#91;1&#93; +"<br>"+

"Number 2 is&#58; "+AA&#91;2&#93; +"<br>"+

"Number 3 is&#58; "+AA&#91;3&#93; + "<br>"+

"Number 4 is &#58; "+AA&#91;4&#93; +"<br>"+

"<br><br>"+

AA&#91;0&#93; + ", you got "+z+" correct out of "+ numberQuestions +"<br><br>" + "Your score is "+ Math.round&#40;&#40;z/ numberQuestions&#41; * 100&#41;+" %"

+"<br><br></body></html>"&#41;;



&#125;


</script>

 

<p><b>Given each of the questions below, check the most appropriate response.</b></p>

<form NAME="id">
<p>Please enter your name <input size="35" type="text" name="input1" rows="1" cols="50"></p>
</form>

<form>
<p>1. What is the newest color M&M?<br><br>

<input type="radio" name="Q1" value="Sorry, the correct answer is D.">Yellow<br>

<input type="radio" name="Q1" value="Sorry, the correct answer is D.">Green<br>

<input type="radio" name="Q1" value="Sorry, the correct answer is D.">Red<br>

<input type="radio" name="Q1" value="correct">Blue<br>

<br>
<br>
</p>
</form>

<form>
<p>2. Which of the following is not an Easter color M&;M?<br><br>

<input type="radio" name="Q2" value="correct">Pastel Orange<br>

<input type="radio" name="Q2" value="Sorry, the correct answer is A.">Pastel Blue<br>

<input type="radio" name="Q2" value="Sorry, the correct answer is A.">Pastel Pink<br>

<input type="radio" name="Q2" value="Sorry, the correct answer is A.">Pastel Green<br>

<br>
<br>
</p>
</form>

<form>

<p>3. Which of the follow M&M's is the only female? &#40;At least the only female in the commercials.&#41;<br><br>

<input type="radio" name="Q3" value="Sorry, the correct answer is C.">Blue<br>

<input type="radio" name="Q3" value="Sorry, the correct answer is C.">Red<br>

<input type="radio" name="Q3" value="correct">Green<br>

<input type="radio" name="Q3" value="Sorry, the correct answer is C.">Yellow<br>

<br>
<br>
</p>
</form>

<form>

<p>4. What color M&M was recently retired?<br><br>

<input type="radio" name="Q4" value="Sorry, the correct answer is B.">Brown<br>

<input type="radio" name="Q4" value="correct">Tan<br>

<input type="radio" name="Q4" value="Sorry, the correct answer is B.">Black<br>

<input type="radio" name="Q4" value="Sorry, the correct answer is B.">Grey<br>

<br>
<br>
</p>
</form>

<form>

<p><input type="button" name="answers" value="Click here for answers" onclick="first&#40;&#41;">
<input type="button" name="close" value="Click here to close answer window" onclick="results.close&#40;&#41;;"> </p>

</form>

<br>

</body>

</html>
Εικόνα

Sotos
Δημοσιεύσεις: 7
Εγγραφή: 10 Απρ 2007 22:14

Eναλακτικες λυσεις για το window.open ??

Δημοσίευση από Sotos » 13 Απρ 2007 13:35

Ευχαριστο παρα μα παρα πολυ φιλε μου!!Δουλεψε οπως μου ειπες :) .

Απάντηση

Επιστροφή στο “JavaScript και Frameworks”

Μέλη σε σύνδεση

Μέλη σε αυτήν τη Δ. Συζήτηση: Δεν υπάρχουν εγγεγραμμένα μέλη και 0 επισκέπτες