簡體   English   中英

新窗口將無法正確加載

[英]new window will not load correctly

我正在制作游戲並向其中添加教程。 我嘗試將鏈接指向“食譜”,因為我稱之為網站,但它每天都在過期。 因此,為了解決這個問題,我打開了一個包含其內容的新窗口。 唯一的問題是它不能正確工作。 當我打開窗戶時,它似乎會重復兩次。 在下面的代碼示例中,我對它進行了格式化,以使其比全部一行更易於閱讀。 謝謝您的幫助

 function newWindow() { myWindow = window.open("", "myWindow", "width=900,height=500"); myWindow.document.write("<!DOCTYPE html> <html> <head> <title> RSS Earth Recipies</title> <style> body{ background-color: #f4dc42; } </style> </head> <body> <p> <h3>Shop:</h3> <br>Fire = 5 Wood<br> Lumber Jack = 10 Fire and consumes one fire and water per second<br> House = 50 Wood and 50 Fire<br> Furnace = 30 Wood and takes one Wood to output on fire<br> Soldier x 10 = -1 Barracks, 10 water and food and consumes 1 food and water per second<br> Barracks = 10 houses <br> Wells = 20 Wood and 5 Food and consumes 1 Food per second but outputs 2 Water per second <br> Hunter = 10 Wood and 5 Water and consumes 1 Water per second but outputs 2 Food per second<br> Breeders = 1 house and consumes 1 Fire, Water, and Food per second<br> <h3>In case you didn't know</h3> <br><ul> <li>Every 30 minutes barbarians will raid your civilization and every hour a nation will sweep your civilization.</li> <li>The number of barbarians can list from 1 to 1000 but for the nation it can go from 1 to 1 Million</li> <li>This versoin of the game's <b>DESIGN</b> was only made for the 1:1 student laptops that were distributed by onslow conty schools</li> <li>If you press F12 then you will find various things in the inspector</li> <li>Press the '/' key and help will pop up</li> </ul> </p> <br> <hr> <h1>Tutorial:</h1> <br> <ol> <li>To start things off The first thing you should do is collect wood. You can do this by either pressing the 'Collect Wood' button at the bottom of the webpage or by pressing the 'w' key</li> <li>Collect at least 30 wood to continue</li> <li>When you have this collect 30 of both Food and Water. You can do this by pressing the 'Collect Food' and 'Collect Water' buttons at the bottom of the webpage or by pressing the 'q' key for water and the 'o' key for food.</li><li>Now that you have this, we can begin 'automated production' as i like to call it. Quickly press the 'Build Well' and 'Train Hunter' buttons at the bottom of the webpage <b>ONCE</b>. Now your civilization is off to a good start!</li> <li>When your feeling kind of lost again turn your wood into fire. Remember 5 wood will give you 1 fire.</li><li>So you have that now when you collect 5 fire just go ahead and press the 'Train Lumber Jack' at the bottom of the webpage. Remember: a Lumber Jack will take up 1 food and water per second</li><li>Next when your ready, make sure you have 30 wood and buy a furnace. You can do this by pressing the 'Make Furnace' button at the bottom of the webpage. This will output one fire per second and will destroy one wood per second</li><li>Moving on to houses and barracks. A house will do good for you if you want to get breeders but their also good if you want to train an army. Houses can be converted into barrack if you have the right amount. In order to make a house you have to have 50 wood and fire.</li> <li>The only reason Barracks are in the game is for the soldiers. Cant have an army with out a storage unit can you? Anyway thats basically the only reasoning you have Barracks. When you buy soldiers you will destroy the amount of Barracks nessesary in order to get troops</li><li>The deal with troops is to give your town a defence against Barbarians, nations, continents, and soon other players! But having troops comes with a cost. The lowest amount of troops you can train at one time is 10 and being that each one accounts for taking in 1 food and water per second your going to need a lot of food and water production!</li> <li>Now were near the end of the tutorial. This last segment will be about Breeders. Breeders are used for population. Population is shown just above the earth right under the season stats. The reason why these are so useful is because you can convert your current population to either Lumber Jacks or Soldiers. Now in order to convert Population into Soldiers you will need to have at least one Barrack in town. Also keep in mind that the amount that you convert is the amount you have to provide for... Resource wise.</li><h3>Thank you for reading the tutorial! Best of luck!</h3><hr><br><h4><i>Liam Sperry</i></ol></body></html> } 
 <a onclick="newWindow()">view recipies</a> 

您可以嘗試這種方式,讓我知道是否可行。

function newWindow() {
    myWindow = window.open("", "myWindow", "width=900,height=500");
    myWindow.document.write("<!DOCTYPE html><html><head><title> RSS Earth Recipies</title><style>body{  background-color: #f4dc42;}</style></head><body><p><h3>Shop:</h3><br>Fire = 5 Wood<br> Lumber Jack = 10 Fire and consumes one fire and water per second<br> House = 50 Wood and 50 Fire<br> Furnace = 30 Wood and takes one Wood to output on fire<br>Soldier x 10 = -1 Barracks, 10 water and food and consumes 1 food and water per second<br>Barracks = 10 houses <br> Wells = 20 Wood and 5 Food and consumes 1 Food per second but outputs 2 Water per second <br> Hunter = 10 Wood and 5 Water and consumes 1 Water per second but outputs 2 Food per second<br>Breeders = 1 house and consumes 1 Fire, Water, and Food per second<br><h3>In case you didn't know</h3><br><ul><li>Every 30 minutes barbarians will raid your civilization and every hour a nation will sweep your civilization.</li><li>The number of barbarians can list from 1 to 1000 but for the nation it can go from 1 to 1 Million</li><li>This versoin of the game's <b>DESIGN</b> was only made for the 1:1 student laptops that were distributed by onslow conty schools</li><li>If you press F12 then you will find various things in the inspector</li><li>Press the '/' key and help will pop up</li></ul></p><br><hr><h1>Tutorial:</h1><br><ol><li>To start things off The first thing you should do is collect wood. You can do this by either pressing the 'Collect Wood' button at the bottom of the webpage or by pressing the 'w' key</li><li>Collect at least 30 wood to continue</li><li>When you have this collect 30 of both Food and Water. You can do this by pressing the 'Collect Food' and 'Collect Water' buttons at the bottom of the webpage or by pressing the 'q' key for water and the 'o' key for food.</li><li>Now that you have this, we can begin 'automated production' as i like to call it. Quickly press the 'Build Well' and 'Train Hunter' buttons at the bottom of the webpage <b>ONCE</b>. Now your civilization is off to a good start!</li><li>When your feeling kind of lost again turn your wood into fire. Remember 5 wood will give you 1 fire.</li><li>So you have that now when you collect 5 fire just go ahead and press the 'Train Lumber Jack' at the bottom of the webpage. Remember: a Lumber Jack will take up 1 food and water per second</li><li>Next when your ready, make sure you have 30 wood and buy a furnace. You can do this by pressing the 'Make Furnace' button at the bottom of the webpage. This will output one fire per second and will destroy one wood per second</li><li>Moving on to houses and barracks. A house will do good for you if you want to get breeders but their also good if you want to train an army. Houses can be converted into barrack if you have the right amount. In order to make a house you have to have 50 wood and fire.</li><li>The only reason Barracks are in the game is for the soldiers. Cant have an army with out a storage unit can you? Anyway thats basically the only reasoning you have Barracks. When you buy soldiers you will destroy the amount of Barracks nessesary in order to get troops</li><li>The deal with troops is to give your town a defence against Barbarians, nations, continents, and soon other players! But having troops comes with a cost. The lowest amount of troops you can train at one time is 10 and being that each one accounts for taking in 1 food and water per second your going to need a lot of food and water production!</li><li>Now were near the end of the tutorial. This last segment will be about Breeders. Breeders are used for population. Population is shown just above the earth right under the season stats. The reason why these are so useful is because you can convert your current population to either Lumber Jacks or Soldiers. Now in order to convert Population into Soldiers you will need to have at least one Barrack in town. Also keep in mind that the amount that you convert is the amount you have to provide for... Resource wise.</li><h3>Thank you for reading the tutorial! Best of luck!</h3><hr><br><h4><i>Liam Sperry</i></ol></body></html>"
}

我只是刪除空格,然后輸入使用的u。 現在正在工作。 您不能在這樣的字符串中輸入:

var string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque quis eros lorem. Quisque eu ultricies nunc, et fermentum dui. Integer quis elementum nunc. Nullam a tempus nibh. // just entered here
     Lorem ipsum dolor sit amet, consectetur adipiscing elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Aliquam rutrum tristique tincidunt. Fusce mollis scelerisque mauris, non porttitor est egestas sed. Curabitur elementum, augue nec finibus tincidunt, nunc leo fermentum sapien, quis lobortis enim nunc at justo."

如果您有這樣的字符串,並且您想以這種方式使用它,則可以在這樣的內部字符串中使用+

var string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque quis eros lorem. Quisque eu ultricies nunc, et fermentum dui. Integer quis elementum nunc. Nullam a tempus nibh."+
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Aliquam rutrum tristique tincidunt. Fusce mollis scelerisque mauris, non porttitor est egestas sed. Curabitur elementum, augue nec finibus tincidunt, nunc leo fermentum sapien, quis lobortis enim nunc at justo.";

希望這會有所幫助:)

請改用innerHTML覆蓋HTML,而不要寫已有的內容。 http://codepen.io/anon/pen/dNVoRd

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM