Tuesday, April 28, 2009

Workaround for Back button issue in FCKeditor.


FCKeditor is very useful tool for allowing the user to enter the formatted text in a webpage without having knowledge in HTML.

If we click Back button in the browser once after entering content using FCKeditor, the browser won't go to actual previous page, instead it will remain in samepage with the empty content. We noticed that clicking Back button two times displays correct previous page.

To avoid this issue, we have used below workaround.

- We provided a separate back button in the webpage. In the onclick event of this button, we called a javascript method to simulate clicking of browser back button two times.

- Find below the sample code.

<button onclick="javascript:history.go(-2);">Back</button>

And also, we have noticed that sometimes (e.g. after saving the content) we need to click browser back button 4 times to go the previous page.

To handle this scenario, we can enhance the above sample code by replacing -2 with a PHP variable whose value should be set either -2 or -4.

for example,

- pass a querystring parameter confim=updated once after finishing the save operation.

- use below code to assign value for a php variable based on the flow.

if (isset($_GET['confirm']))
{
$backcount=-4;
}
else
{
$backcount=-2;
}


- Now this php variable can be used in our previous sample code.

<button onclick="javascript:history.go(<?php echo $backcount;?>);"> Back</button>

updates on May 08:

It seems we need to use "return false" as below to avoid issue in some browsers (IE 7 and FireFox).

<button onclick="javascript:history.go(<?php echo $backcount;?>);return false;" > Back</button>

More Articles...

No comments:

Search This Blog