Jump to content

javascript to php


ercantan

Recommended Posts

Hi all,

i ve got a javascript code. but i want to use a php function instead of this javascript code. You know, some people block javascripts, due to this reason i would like to use server side coding. However, i could not write a php function yet. Any help would be great for me.

here is my java script code:

 

<html>

<body>

<table>

<tr>

<td>

<img id="bigImage" src="images/spacer.gif">

<--!

my other contents.

!-->

</td>

</tr>

</table>

 

<script type="text/javascript">

function LoadImage()

{

if (document.getElementById("bigImage")) {

document.getElementById("bigImage").src="images/big.gif";

}

}

LoadImage();

</script>

 

</body>

</html>

 

------------------------

Acutually, im using this javascript code in php file. i wrote codes in html to show you basicly.

Thank you to all friends

With best regards

Link to comment
https://forums.phpfreaks.com/topic/176562-javascript-to-php/
Share on other sites

Hi MrAdam,

 

Thanks for your answer. I have got a big image (100Kb) in header of main page. Browsers load this image firstly, after than loads other content. so, it takes really long time. i think, waiting this image is fully unneeded. with this javascript, browser load small blank image (1 pixel) firstly, after than loads other contents, and finally, change small image to big image.

 

thanks again.

Link to comment
https://forums.phpfreaks.com/topic/176562-javascript-to-php/#findComment-930754
Share on other sites

Hi

 

Not really any way to do it beyond what you have.

 

Once the page has loaded that is the end of php for that page. You can use AJAX to call php from a loaded page, but that too relies on javascript.

 

You could possibly use CSS to set the image, as that should happen once the page is loaded.

 

All the best

 

Keith

Link to comment
https://forums.phpfreaks.com/topic/176562-javascript-to-php/#findComment-930778
Share on other sites

Unfortunately there's no PHP alternative to that code. It relies on being able to modify the DOM after the page has loaded- which PHP cannot do (as it's processed server-side before you start loading the page). I wouldn't rely on JavaScript for this either to be honest, as you say users could disable it. The best solution I think would be to try to lower the file size of the image. Perhaps try lowering the quality of the image (whilst it doesn't visually loose quality), and try using image optimization tools like Smuth.it.

Link to comment
https://forums.phpfreaks.com/topic/176562-javascript-to-php/#findComment-930781
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.