document.write()

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

document.write()

Post 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');
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: document.write()

Post 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.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: document.write()

Post 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?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: document.write()

Post 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.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: document.write()

Post 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>


Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: document.write()

Post by Vegan »

my goal is to replace the FB like line with JavaScript to use the current page URL

self.location.href
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: document.write()

Post 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.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: document.write()

Post 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?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: document.write()

Post 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?
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: document.write()

Post 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'));
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: document.write()

Post by califdon »

I want to help you if I can, but you're not responding to my questions.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: document.write()

Post 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
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: document.write()

Post 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.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: document.write()

Post by Vegan »

I have abandoned the thing, could not get it to work as desired.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Post Reply