| $€£ Money Maker.
Join Date: 2011 Location: Australia
Posts: 316
Thanks: 67
Thanked 31 Times in 21 Posts
| Re: SEO for Javascript Site! Help! Originally Posted by bestbuddy1986 the easiest is using javascript’s document.write:
<script type="text/javascript">
document.write('Hello World');
</script>
This works great for simple little messages, but what if you have a large multi-line text string? What if your text has HTML tags and double quotes in it? Then you’re in for some trouble, because the nice little javascript examples will die on you most ingloriously. PHP to the rescue. Use PHP to replace the spaces (and double-quotes)… you may have to escape your double-quotes in the source text.
Extending that simple little example with some meaty text and some PHP, you end up with something like this:
<?php Originally Posted by bestbuddy1986 the easiest is using javascript’s document.write:
<script type="text/javascript">
document.write('Hello World');
</script>
This works great for simple little messages, but what if you have a large multi-line text string? What if your text has HTML tags and double quotes in it? Then you’re in for some trouble, because the nice little javascript examples will die on you most ingloriously. PHP to the rescue. Use PHP to replace the spaces (and double-quotes)… you may have to escape your double-quotes in the source text.
Extending that simple little example with some meaty text and some PHP, you end up with something like this:
<?php
$text = ”
<p>
Hello,
big, multi-line
”stuff”, watch out!
</p>
“;
$text = preg_replace(“/s+/”,” “,$text);
$text = preg_replace(‘/\”/’,”””,$text);
?>
<script type=”text/javascript”>
document.write(‘<?php echo $text; ?>’);
</script>
That solution works (at least, it did before I had to replace all the tags with html entities to make this post). The text gets written at that point in the document once it loads on the client-side. Notice that the regular expressions replace double-quotes with 2 single quotes (tricky, eh?), and any excessive space is replaced. But what if you want something more complicated… what if you don’t like the regular expressions and having to escape your double-quotes? The above method is sorta techie for some, and prone to error. There is another solution: use an Ajax library to pipe HTML directly to a div tag. This solution is more scalable because you can put all the HTML in a separate file, and you don’t have to escape characters.
Download this Javascript library from Prototype JavaScript framework: Easy Ajax and DOM manipulation for dynamic web applications and copy the file somewhere in your site’s html directory (here I called it div_updater.js and put it in my js directory). Reference the file in a script tag using the ‘src’ element, then use the Ajax.Updater function to specify 1) the div id where the text should be written and 2) the file to be included.
<div id="target_div"></div>
<script type="text/javascript" src="js/div_updater.js"></script>
<script type="text/javascript">
new Ajax.Updater('target_div', 'include_file.php');
</script>
This solution will write the text to where-ever you have the target_div. Just make sure you use give the div an ‘id’ and that its name is referenced correctly by the Updater function. Using one of these solutions, you can utilize javascript to hide text from the search engines. |
Wow great info thanks but on the upside for the way my site is set up at the moment I believe it would be to hard to implement that. It was suggested to me before to use a bit of AJAX and just have one page which refreshes the image, but I tried this it was literally about 10x slower.
Will keep this in mind though for a later date thanks. = ”
<p>
Hello,
big, multi-line
”stuff”, watch out!
</p>
“; Originally Posted by bestbuddy1986 the easiest is using javascript’s document.write:
<script type="text/javascript">
document.write('Hello World');
</script>
This works great for simple little messages, but what if you have a large multi-line text string? What if your text has HTML tags and double quotes in it? Then you’re in for some trouble, because the nice little javascript examples will die on you most ingloriously. PHP to the rescue. Use PHP to replace the spaces (and double-quotes)… you may have to escape your double-quotes in the source text.
Extending that simple little example with some meaty text and some PHP, you end up with something like this:
<?php
$text = ”
<p>
Hello,
big, multi-line
”stuff”, watch out!
</p>
“;
$text = preg_replace(“/s+/”,” “,$text);
$text = preg_replace(‘/\”/’,”””,$text);
?>
<script type=”text/javascript”>
document.write(‘<?php echo $text; ?>’);
</script>
That solution works (at least, it did before I had to replace all the tags with html entities to make this post). The text gets written at that point in the document once it loads on the client-side. Notice that the regular expressions replace double-quotes with 2 single quotes (tricky, eh?), and any excessive space is replaced. But what if you want something more complicated… what if you don’t like the regular expressions and having to escape your double-quotes? The above method is sorta techie for some, and prone to error. There is another solution: use an Ajax library to pipe HTML directly to a div tag. This solution is more scalable because you can put all the HTML in a separate file, and you don’t have to escape characters.
Download this Javascript library from Prototype JavaScript framework: Easy Ajax and DOM manipulation for dynamic web applications and copy the file somewhere in your site’s html directory (here I called it div_updater.js and put it in my js directory). Reference the file in a script tag using the ‘src’ element, then use the Ajax.Updater function to specify 1) the div id where the text should be written and 2) the file to be included.
<div id="target_div"></div>
<script type="text/javascript" src="js/div_updater.js"></script>
<script type="text/javascript">
new Ajax.Updater('target_div', 'include_file.php');
</script>
This solution will write the text to where-ever you have the target_div. Just make sure you use give the div an ‘id’ and that its name is referenced correctly by the Updater function. Using one of these solutions, you can utilize javascript to hide text from the search engines. |
Wow great info thanks but on the upside for the way my site is set up at the moment I believe it would be to hard to implement that. It was suggested to me before to use a bit of AJAX and just have one page which refreshes the image, but I tried this it was literally about 10x slower.
Will keep this in mind though for a later date thanks. = preg_replace(“/s+/”,” “, Originally Posted by bestbuddy1986 the easiest is using javascript’s document.write:
<script type="text/javascript">
document.write('Hello World');
</script>
This works great for simple little messages, but what if you have a large multi-line text string? What if your text has HTML tags and double quotes in it? Then you’re in for some trouble, because the nice little javascript examples will die on you most ingloriously. PHP to the rescue. Use PHP to replace the spaces (and double-quotes)… you may have to escape your double-quotes in the source text.
Extending that simple little example with some meaty text and some PHP, you end up with something like this:
<?php
$text = ”
<p>
Hello,
big, multi-line
”stuff”, watch out!
</p>
“;
$text = preg_replace(“/s+/”,” “,$text);
$text = preg_replace(‘/\”/’,”””,$text);
?>
<script type=”text/javascript”>
document.write(‘<?php echo $text; ?>’);
</script>
That solution works (at least, it did before I had to replace all the tags with html entities to make this post). The text gets written at that point in the document once it loads on the client-side. Notice that the regular expressions replace double-quotes with 2 single quotes (tricky, eh?), and any excessive space is replaced. But what if you want something more complicated… what if you don’t like the regular expressions and having to escape your double-quotes? The above method is sorta techie for some, and prone to error. There is another solution: use an Ajax library to pipe HTML directly to a div tag. This solution is more scalable because you can put all the HTML in a separate file, and you don’t have to escape characters.
Download this Javascript library from Prototype JavaScript framework: Easy Ajax and DOM manipulation for dynamic web applications and copy the file somewhere in your site’s html directory (here I called it div_updater.js and put it in my js directory). Reference the file in a script tag using the ‘src’ element, then use the Ajax.Updater function to specify 1) the div id where the text should be written and 2) the file to be included.
<div id="target_div"></div>
<script type="text/javascript" src="js/div_updater.js"></script>
<script type="text/javascript">
new Ajax.Updater('target_div', 'include_file.php');
</script>
This solution will write the text to where-ever you have the target_div. Just make sure you use give the div an ‘id’ and that its name is referenced correctly by the Updater function. Using one of these solutions, you can utilize javascript to hide text from the search engines. |
Wow great info thanks but on the upside for the way my site is set up at the moment I believe it would be to hard to implement that. It was suggested to me before to use a bit of AJAX and just have one page which refreshes the image, but I tried this it was literally about 10x slower.
Will keep this in mind though for a later date thanks.); Originally Posted by bestbuddy1986 the easiest is using javascript’s document.write:
<script type="text/javascript">
document.write('Hello World');
</script>
This works great for simple little messages, but what if you have a large multi-line text string? What if your text has HTML tags and double quotes in it? Then you’re in for some trouble, because the nice little javascript examples will die on you most ingloriously. PHP to the rescue. Use PHP to replace the spaces (and double-quotes)… you may have to escape your double-quotes in the source text.
Extending that simple little example with some meaty text and some PHP, you end up with something like this:
<?php
$text = ”
<p>
Hello,
big, multi-line
”stuff”, watch out!
</p>
“;
$text = preg_replace(“/s+/”,” “,$text);
$text = preg_replace(‘/\”/’,”””,$text);
?>
<script type=”text/javascript”>
document.write(‘<?php echo $text; ?>’);
</script>
That solution works (at least, it did before I had to replace all the tags with html entities to make this post). The text gets written at that point in the document once it loads on the client-side. Notice that the regular expressions replace double-quotes with 2 single quotes (tricky, eh?), and any excessive space is replaced. But what if you want something more complicated… what if you don’t like the regular expressions and having to escape your double-quotes? The above method is sorta techie for some, and prone to error. There is another solution: use an Ajax library to pipe HTML directly to a div tag. This solution is more scalable because you can put all the HTML in a separate file, and you don’t have to escape characters.
Download this Javascript library from Prototype JavaScript framework: Easy Ajax and DOM manipulation for dynamic web applications and copy the file somewhere in your site’s html directory (here I called it div_updater.js and put it in my js directory). Reference the file in a script tag using the ‘src’ element, then use the Ajax.Updater function to specify 1) the div id where the text should be written and 2) the file to be included.
<div id="target_div"></div>
<script type="text/javascript" src="js/div_updater.js"></script>
<script type="text/javascript">
new Ajax.Updater('target_div', 'include_file.php');
</script>
This solution will write the text to where-ever you have the target_div. Just make sure you use give the div an ‘id’ and that its name is referenced correctly by the Updater function. Using one of these solutions, you can utilize javascript to hide text from the search engines. |
Wow great info thanks but on the upside for the way my site is set up at the moment I believe it would be to hard to implement that. It was suggested to me before to use a bit of AJAX and just have one page which refreshes the image, but I tried this it was literally about 10x slower.
Will keep this in mind though for a later date thanks. = preg_replace(‘/\”/’,”””, Originally Posted by bestbuddy1986 the easiest is using javascript’s document.write:
<script type="text/javascript">
document.write('Hello World');
</script>
This works great for simple little messages, but what if you have a large multi-line text string? What if your text has HTML tags and double quotes in it? Then you’re in for some trouble, because the nice little javascript examples will die on you most ingloriously. PHP to the rescue. Use PHP to replace the spaces (and double-quotes)… you may have to escape your double-quotes in the source text.
Extending that simple little example with some meaty text and some PHP, you end up with something like this:
<?php
$text = ”
<p>
Hello,
big, multi-line
”stuff”, watch out!
</p>
“;
$text = preg_replace(“/s+/”,” “,$text);
$text = preg_replace(‘/\”/’,”””,$text);
?>
<script type=”text/javascript”>
document.write(‘<?php echo $text; ?>’);
</script>
That solution works (at least, it did before I had to replace all the tags with html entities to make this post). The text gets written at that point in the document once it loads on the client-side. Notice that the regular expressions replace double-quotes with 2 single quotes (tricky, eh?), and any excessive space is replaced. But what if you want something more complicated… what if you don’t like the regular expressions and having to escape your double-quotes? The above method is sorta techie for some, and prone to error. There is another solution: use an Ajax library to pipe HTML directly to a div tag. This solution is more scalable because you can put all the HTML in a separate file, and you don’t have to escape characters.
Download this Javascript library from Prototype JavaScript framework: Easy Ajax and DOM manipulation for dynamic web applications and copy the file somewhere in your site’s html directory (here I called it div_updater.js and put it in my js directory). Reference the file in a script tag using the ‘src’ element, then use the Ajax.Updater function to specify 1) the div id where the text should be written and 2) the file to be included.
<div id="target_div"></div>
<script type="text/javascript" src="js/div_updater.js"></script>
<script type="text/javascript">
new Ajax.Updater('target_div', 'include_file.php');
</script>
This solution will write the text to where-ever you have the target_div. Just make sure you use give the div an ‘id’ and that its name is referenced correctly by the Updater function. Using one of these solutions, you can utilize javascript to hide text from the search engines. |
Wow great info thanks but on the upside for the way my site is set up at the moment I believe it would be to hard to implement that. It was suggested to me before to use a bit of AJAX and just have one page which refreshes the image, but I tried this it was literally about 10x slower.
Will keep this in mind though for a later date thanks.);
?>
<script type=”text/javascript”>
document.write(‘<?php echo Originally Posted by bestbuddy1986 the easiest is using javascript’s document.write:
<script type="text/javascript">
document.write('Hello World');
</script>
This works great for simple little messages, but what if you have a large multi-line text string? What if your text has HTML tags and double quotes in it? Then you’re in for some trouble, because the nice little javascript examples will die on you most ingloriously. PHP to the rescue. Use PHP to replace the spaces (and double-quotes)… you may have to escape your double-quotes in the source text.
Extending that simple little example with some meaty text and some PHP, you end up with something like this:
<?php
$text = ”
<p>
Hello,
big, multi-line
”stuff”, watch out!
</p>
“;
$text = preg_replace(“/s+/”,” “,$text);
$text = preg_replace(‘/\”/’,”””,$text);
?>
<script type=”text/javascript”>
document.write(‘<?php echo $text; ?>’);
</script>
That solution works (at least, it did before I had to replace all the tags with html entities to make this post). The text gets written at that point in the document once it loads on the client-side. Notice that the regular expressions replace double-quotes with 2 single quotes (tricky, eh?), and any excessive space is replaced. But what if you want something more complicated… what if you don’t like the regular expressions and having to escape your double-quotes? The above method is sorta techie for some, and prone to error. There is another solution: use an Ajax library to pipe HTML directly to a div tag. This solution is more scalable because you can put all the HTML in a separate file, and you don’t have to escape characters.
Download this Javascript library from Prototype JavaScript framework: Easy Ajax and DOM manipulation for dynamic web applications and copy the file somewhere in your site’s html directory (here I called it div_updater.js and put it in my js directory). Reference the file in a script tag using the ‘src’ element, then use the Ajax.Updater function to specify 1) the div id where the text should be written and 2) the file to be included.
<div id="target_div"></div>
<script type="text/javascript" src="js/div_updater.js"></script>
<script type="text/javascript">
new Ajax.Updater('target_div', 'include_file.php');
</script>
This solution will write the text to where-ever you have the target_div. Just make sure you use give the div an ‘id’ and that its name is referenced correctly by the Updater function. Using one of these solutions, you can utilize javascript to hide text from the search engines. |
Wow great info thanks but on the upside for the way my site is set up at the moment I believe it would be to hard to implement that. It was suggested to me before to use a bit of AJAX and just have one page which refreshes the image, but I tried this it was literally about 10x slower.
Will keep this in mind though for a later date thanks.; ?>’);
</script>
That solution works (at least, it did before I had to replace all the tags with html entities to make this post). The text gets written at that point in the document once it loads on the client-side. Notice that the regular expressions replace double-quotes with 2 single quotes (tricky, eh?), and any excessive space is replaced. But what if you want something more complicated… what if you don’t like the regular expressions and having to escape your double-quotes? The above method is sorta techie for some, and prone to error. There is another solution: use an Ajax library to pipe HTML directly to a div tag. This solution is more scalable because you can put all the HTML in a separate file, and you don’t have to escape characters.
Download this Javascript library from Prototype JavaScript framework: Easy Ajax and DOM manipulation for dynamic web applications and copy the file somewhere in your site’s html directory (here I called it div_updater.js and put it in my js directory). Reference the file in a script tag using the ‘src’ element, then use the Ajax.Updater function to specify 1) the div id where the text should be written and 2) the file to be included.
<div id="target_div"></div>
<script type="text/javascript" src="js/div_updater.js"></script>
<script type="text/javascript">
new Ajax.Updater('target_div', 'include_file.php');
</script>
This solution will write the text to where-ever you have the target_div. Just make sure you use give the div an ‘id’ and that its name is referenced correctly by the Updater function. Using one of these solutions, you can utilize javascript to hide text from the search engines. |
Wow great info thanks but on the upside for the way my site is set up at the moment I believe it would be to hard to implement that. It was suggested to me before to use a bit of AJAX and just have one page which refreshes the image, but I tried this it was literally about 10x slower.
Will keep this in mind though for a later date thanks.
|