Author Topic: Cannot create link with document.write  (Read 170 times)

Nikos

  • Guest
Cannot create link with document.write
« on: January 30, 2012, 12:20:19 PM »
I have a html file like the below, that calls a php file

Code: [Select]
<html>
<head>
</head>
<body>
  <script language="javascript" src="noname1.php"></script>
</body>
</html>

In the php file I just want to create a link, but I only get simple text.
The php file is the following

Code: [Select]
<?php
  
echo 'document.write("<a href=\"http://google.com\" target=\"_blank\">Bring me to google</a>")';
?>

Smokey PHP

  • Web Developer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 529
  • Karma: +5/-0
    • View Profile
Re: Cannot create link with document.write
« Reply #1 on: January 30, 2012, 04:41:12 PM »
Try putting this line at the top of the PHP file:

PHP Code: [Select]
header("content-type: application/x-javascript");

dueller

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Cannot create link with document.write
« Reply #2 on: January 30, 2012, 05:00:17 PM »
No use.
You can try it at home, there are only 2 files. Very strange behavior.

Smokey PHP

  • Web Developer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 529
  • Karma: +5/-0
    • View Profile
Re: Cannot create link with document.write
« Reply #3 on: January 31, 2012, 02:22:19 PM »
Works fine for me - go to the php file and see what that's outputting, and (if you're using firefox) you can also go back to the main page, select all, then right click and view selection source

dueller

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Cannot create link with document.write
« Reply #4 on: January 31, 2012, 03:20:06 PM »
Yes, it is working fine. It should be some strange char.
Firefox showed
<a href="http: xmlns="http://www.w3.org/1999/xhtml" "=""
I still cannot find that strange char.