A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearjavascript function not behaving correctly - page 1
User InfoPosts
javascript function not behaving correctly#1
I have this little function

function makewindows(){
child1 = window.open ("about:blank");
child1.document.write("<?php echo htmlspecialchars(json_encode($row2['ARTICLE_DESC']), ENT_QUOTES); ?>");
child1.document.close();
}


Which whatever I try, simply outputs the php code as the html source, and not the result of the php code. This was previously working fine, and I am not sure what I have changed to result in this behavior.

I have pasted all the code now. An error is generated by a link that calls updateByQuery, preventing makewindows from being parsed correctly..I think. I am not sure what is wrong with updateByQuery however:

function updateByQuery(layer, query) {
url = "get_records.php?cmd=GetRecordSet&query="+query+"&sid="+Math.random();
update(layer, url);
}

posted date: 2008-12-15 04:18:00


Re: javascript function not behaving correctly#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-15 04:18:01


Re: javascript function not behaving correctly#3
This code must be in a file that is parsed by PHP before being sent to the browser. Make sure it has a ".php" extension (or that Apache/(or other) is configured to put whatever extension it is using through PHP). Also, make sure PHP is installed correctly and working.

posted date: 2008-12-15 04:24:00


Re: javascript function not behaving correctly#4
Have you recently moved this file out of a PHP parsed file (i.e. .phtml/.php) and into a .js file? Note that any PHP you expect to be executed must be parsed by the PHP parser before delivery to the client. If it was originally in a .php file, then it would have been parsed/ executed, and worked fine.However, .js files are not, by default, parsed by PHP. Perhaps they were, at one point, but your server administrator has recently upgraded something, and lost this behaviour? You may be able to use a local configuration file (in Apache, .htaccess) to re-enable it.

posted date: 2008-12-15 04:26:00


Re: javascript function not behaving correctly#5
Make sure you are running the page from the webserver like such: http://localhost/yourpage.php and not directly from the file itself like such: file://yourpage.php

posted date: 2008-12-15 04:28:00


Re: javascript function not behaving correctly#6
I assume you still have it in a file that is parsed by PHP, like the others already have said. Then it is probably something above this code snippet that confuses the php-parser so it don't recognize the php-tag.To test that, try to output something else before this function, maybe just a comment or something. Also, use "var" before client1, or else client1 will be in the global scope.update 1Since you tried to insert a piece of php-code and it broke, then the problem is that the server don't parse the file as it should.To test if the server really parses your .js files (its not the default setting I believe), create a new file: test.js<?php echo "This is a test"; ?>Open the test.js file in your browser and look at the page source. If it has the php tags your server don't parse .js files. update 2If the php works in .js files, try to rewrite the function like this (sorry I have not tested it because I don't have access to a php-server right now)<?php echo "function makewindows(){var child1 = window.open (\"about:blank\"); " ."child1.document.write(\"" . htmlspecialchars(json_encode($row2['ARTICLE_DESC']), ENT_QUOTES) . "\");" . "child1.document.close(); }"; ?>

posted date: 2008-12-15 04:34:00


Re: javascript function not behaving correctly#7
Putting in a PHP alert definitely breaks it, and causes an error on a link that calls a function above makewindows. I will paste that code now.

posted date: 2008-12-15 04:37:00


Re: javascript function not behaving correctly#8
The file in included in a script tag. I changed things relating to the ajax application, such as other javascript methods in the file.

posted date: 2008-12-15 04:40:00


Re: javascript function not behaving correctly#9
Right now I don't have access to a php-server so I can't test the code.

posted date: 2008-12-15 04:42:00


Re: javascript function not behaving correctly#10
Yes, the problem is that it's not getting parsed.

posted date: 2008-12-15 04:44:00


Re: javascript function not behaving correctly#11
I'm not sure if this will help, but best practices dictate that whenever you write to a new window using JavaScript, you should open and close the document. Can you try this?function makewindows(){ var child1 = window.open ("about:blank"); child1.document.open(); child1.document.write("<?php echo htmlspecialchars(json_encode($row2['ARTICLE_DESC']), ENT_QUOTES); ?>"); child1.document.close(); }

posted date: 2008-12-15 05:35:00


Re: javascript function not behaving correctly#12
I am the administrator, and have not changed anything.

posted date: 2008-12-15 05:52:00


select page: « 1 2 »
Copyright ©2008-2017 www.momige.com, all rights reserved.