-1
Javascriptを使用してページをブタのラテンに翻訳しようとしています。翻訳するロジックがありますが、段落をフェッチできません。 MYウェブページには2つの段落と翻訳ボタンがあります。ボタンをクリックすると、ブタのラテンの同じ段落で新しいウィンドウが開きます。 私のコードを以下に示します。Javascriptでブタのラテンにパラグラフを翻訳する
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title> String Manipulation </title>
<head>
<center><h1 style="color:Blue; font-family:verdana;"> BURJ KHALIFA</h1> <hr>
<img src ="burjkhalifa.jpeg" width = "650" height ="370"></center>
<script type= "text/javascript">
function getTranslate()
{
var text = document.getElementById("pagetitle").value;
newWindow = window.open(text, "myWindow");
var newWindowBody = newWindow.document.getElementsByTagName("body")[0];
newWindowBody.setAttribute("onload", "window.opener.getParagraphs()");
}
function getParagraphs() {
var pElement = newWindow.document.getElementsByTagName("p");
var str='';
for(var counter =0; counter < pElement.length;counter++)
{
document.writeln(translate(pElement[counter].innerHTML));
document.writeln("<p> </p>")
}
}
function translate(word)
{
var array = word.split('');
var vowels = ['a','e','i','o','u'];
var newWord = '';
for(var i = 0; i < vowels.length-1; i++)
{
for(var y = 0; y < array.length-1; y++)
{
if(array[y] == vowels[i])
{
for(var x = y; x < array.length; x++)
{
newWord = newWord + array[x];
}
for(var n = 0; n < y; n++)
{
newWord = newWord + array[n];
}
newWord += "ay";
}
}
}
}
return newWord;
</script>
</head>
<body>
<p style="font-family:courier; font-size:100%;">
The Burj Khalifa, known as the Burj Dubai before its inauguration, is a megatall skyscraper in Dubai,
United Arab Emirates. It has a roof height of 828 m (2,717 ft), and with its antenna included, it stands
a total height of 829.8 m (2,722 ft), making it the tallest building and the tallest structure in the world.
</p>
<p style="font-family:courier; font-size:100%;">
Construction of the Burj Khalifa began in 2004, with the exterior completed 5 years later in 2009. The primary
structure is reinforced concrete. The building was opened in 2010 as part of a new development called Downtown Dubai.
It is designed to be the centrepiece of large-scale, mixed-use development. The decision to build the building is
reportedly based on the government's decision to diversify from an oil-based economy, and for Dubai to gain international
recognition. The building was named in honour of the ruler of Abu Dhabi and president of the United Arab Emirates, Khalifa
bin Zayed Al Nahyan; Abu Dhabi and the UAE government lent Dubai money to pay its debts. The building broke numerous height
records, including its designation as the tallest tower in the world.
</p>
<input type="button" id = "submit" name="" value="Translate" style="color: green; font-size:18pt"size ="10" onclick ="getTranslate()" />
</html>
ブラウザのコンソールにはどのようなエラーが表示されていますか?サイドノートでは、閉じたbodyタグがなく、存在しない '
私は段落を取得できません。翻訳ボタンをクリックすると、何も起こりません。 –
ブラウザのデベロッパーツール(F12)を開き、コンソールでその内容を確認します – j08691