Page 1 of 1

document.write()

Posted: Sun Feb 05, 2012 9:40 pm
by Vegan
I tried to use some JavaScript inside the PHP footer of my gaming site.

It would not display the string as desired

document.write('some text');

Re: document.write()

Posted: Sun Feb 05, 2012 10:22 pm
by califdon
You would have to provide more of your code to get any meaningful response, but if you didn't echo the javascript within javascript tags, of course the browser would not recognize it as javascript code.

Re: document.write()

Posted: Tue Feb 07, 2012 8:18 am
by Vegan
<script type="text/javascript">
document.write('hello')
</script>

wonder what is wrong?

do so I need to echo JavaScript but regular HTML is fine?

Re: document.write()

Posted: Tue Feb 07, 2012 11:54 am
by califdon
Vegan wrote:<script type="text/javascript">
document.write('hello')
</script>

wonder what is wrong?

do so I need to echo JavaScript but regular HTML is fine?
Hard to say without seeing your code. No, there's no difference between JS and HTML in this regard. But it depends on how you wrote it, so without seeing that, there's not much point in discussing it.

Re: document.write()

Posted: Tue Feb 07, 2012 5:45 pm
by Vegan
here is footer.php in its entirety

Code: Select all


<!-- for some reason, PHP for Windows adds newline when it should not for an include -->
<!-- this does not seem to manifest with PHP documents, suggests a defect in the parser -->

<!-- Facebook Like -->
<div class="fb-like" data-href="http://www.hardcore-games.tk" data-send="false" data-width="450" data-show-faces="true"></div>
<br>
<br>



<!-- Copyright -->
<footer>
&copy; 583727 BC LTD, All Rights Reserved. <a href="http://www.hardcore-games.tk/about/legals.php">Legals</a>.&nbsp;  
<?php echo "Last modified: " . date ("F d, Y (H:i:s)", getlastmod()); ?>
</footer>
<br>

<!-- Paypal Donate Button -->
<div class="centered">
	<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
		<input type="hidden" name="cmd" value="_s-xclick">
		<input type="hidden" name="hosted_button_id" value="GVJSYJ6KBVN4C">
		<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
		<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
	</form>
</div>
<br>

<!-- validator buttons -->
<div class="centered">
	<a href="http://jigsaw.w3.org/css-validator/check/referer" target="_blank">
    <img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!"></a>
    
	<a href="http://get.adobe.com/reader/" target="_blank">
	<img alt="Get Adobe Acobat Reader" height="31" src="http://www.hardcore-games.tk/images/getacrobat.gif" width="86"></a>
</div>



Re: document.write()

Posted: Tue Feb 07, 2012 5:47 pm
by Vegan
my goal is to replace the FB like line with JavaScript to use the current page URL

self.location.href

Re: document.write()

Posted: Tue Feb 07, 2012 6:50 pm
by califdon
I'm afraid I don't recognize that syntax at all:
<div class="fb-like" data-href="http://www.hardcore-games.tk" data-send="false" data-width="450" data-show-faces="true"></div>
That appears to be just specifying the name of the CSS class for an empty <div> that will presumably filled with something later in JS. I'm not familiar with those other parameters.

In any case, I don't think you can use document.write() in such a situation. Take a look at http://javascript.crockford.com/script.html, which advises against using document.write().

Perhaps if you explained what you are trying to do, I might be able to help.

Re: document.write()

Posted: Wed Feb 08, 2012 4:04 pm
by Vegan
that line of code is what will show the FB like button, the actual code is in JavaScript loaded in the header

maybe I should use PHP and echo?

Re: document.write()

Posted: Wed Feb 08, 2012 4:16 pm
by califdon
Vegan wrote:that line of code is what will show the FB like button, the actual code is in JavaScript loaded in the header

maybe I should use PHP and echo?
I'm afraid that doesn't tell me anything. Just tell me what you want to do. Why can't you just create the button in your original code?

Re: document.write()

Posted: Mon Feb 13, 2012 7:11 pm
by Vegan
This is the JavaScript part I use in the header called block

Code: Select all

// Facebook Like
(function(d, s, id) {
  	var js, fjs = d.getElementsByTagName(s)[0];
  	if (d.getElementById(id)) {return;}
  	js = d.createElement(s); js.id = id;
  	js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  	fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

Re: document.write()

Posted: Mon Feb 13, 2012 7:27 pm
by califdon
I want to help you if I can, but you're not responding to my questions.

Re: document.write()

Posted: Thu Feb 16, 2012 4:06 pm
by Vegan
the document is HTML5 assembled from the main document, that includes a menu and a footer that is constant for each page

view the source of my home page and you will see all of the document, the comments delineate the PHP includes

Re: document.write()

Posted: Thu Feb 16, 2012 7:37 pm
by califdon
I'm sorry, but we're just not communicating. I don't understand what you are trying to do. I looked at your site and I still have no idea what it is that you want to do. If you want help, you need to say something like "I want to add a hyperlink at ...." or "The hyperlink at .... isn't working" or "I need to change .... to ....". Otherwise, I don't know how to help you.

Re: document.write()

Posted: Tue Feb 21, 2012 10:06 pm
by Vegan
I have abandoned the thing, could not get it to work as desired.