I'm not a php developer and I have a basic knowledge in html.
I currently have this code
<div class="page-header">
<h1 class="<?php echo $this->item->backlink ? "backlink" : ""; ?>">
<?php echo $this->item->backlink ? '<a class="backtomap" href="' . $this->item->backlink . '">' . JText::_('COM_FOCALPOINT_BACK_TO_MAP') . '</a>' : "";
echo trim($this->item->title); ?>
</h1>
</div>
now I want to integrate the history.back function in place of the current
onclick="history.back(-1)"
so that the generated html looks something like
<a class="backtomap" href="#" onclick="history.back(-1)>' . JText::_('COM_FOCALPOINT_BACK_TO_MAP') . '</a>'
I tried to change the code here and there, but without the right knowledge it doesn't really work.
Can anybody help?
Thank you.
Just Change line
'<a class="backtomap" href="' . $this->item->backlink . '">' . JText::_('COM_FOCALPOINT_BACK_TO_MAP') . '</a>'
with
'<a class="backtomap" href="#" onclick="history.back(-1)" >' . JText::_('COM_FOCALPOINT_BACK_TO_MAP') . '</a>'
Related
I'm using this code to open an image in a new window, but i can't get it to work. What is wrong?
echo "
<td align='center'>
<a href='images/spasergjengen/" . $row['Grad'] . "' target='_blank'>
<img src='images/spasergjengen/" . $row['Grad'] . "' width='125' height='150'
title='Spasergjengen' alt='Spasergjengen' />
</a>
<br>
<button onclick='myFunction" . $row['MedlemId'] . "'()'>Se Bilde</button>
<script>
function myFunction" . $row['MedlemId'] . "'() {
window.open('images/spasergjengen/" . $row['Grad'] . "', '_blank',
'toolbar=yes,scrollbars=yes,resizable=yes
,top=200,left=300,width=750,height=565'); }
</script>
</td>
";
[Tested]
<?php echo "<td align='center'><a href='images/spasergjengen/" . $row['Grad'] . "' target='_blank'><img src='images/spasergjengen/" . $row['Grad'] . "' width='125' height='150' title='Spasergjengen' alt='Spasergjengen' /></a><br><button onclick='myFunction" . $row['MedlemId'] . "()'>Se Bilde</button>
<script> function myFunction" . $row['MedlemId'] . "() { window.open('images/spasergjengen/" . $row['Grad'] . ",_blank', 'toolbar=yes,scrollbars=yes,resizable=yes,top=200,left=300,width=750,height=565'); } </script></td>";
?>
Here is my some code where I create a button at the backend side. And I have put an URL into the function. But on my frontend side url slashes are replaced into white spaces. I don't know why it is happening. Please Help me
$usrRows[] = '<button type="button" name="delete" id="' . $value->id . '" onclick="SDelete("' . route('ajax-delete') . '", "' . $tableName . '", ' . $value->id . ')" class="btn btn-danger btn-xs delete" >Delete</button>';
]1
into onclick function, it shows me without slashes.
Laravel blade by default escapes HTML strings to avoid XSS attack so instead of
#foreach($usrRows[] as $row)
{{ $row }}
#endforeach
Inform blade not to escape anything like this
#foreach($usrRows[] as $row)
{!! $row !!}
#endforeach
You have to add "/" manually by yourself ajax public route does not give us "/" even if we can view in other part when we have public files.
$usrRows[] = '<button type="button" name="delete" id="' . $value->id . '" onclick="SDelete("' . '/' . route('ajax-delete') . '", "' . $tableName . '", ' . $value->id . ')" class="btn btn-danger btn-xs delete" >Delete</button>';
This is driving me nuts.
I have a button on my php template
echo '<a href="'. esc_url($action_link) .'" class="action_button'. esc_attr($action_class) .'" '. wp_kses_data($action_target) .'>'. wp_kses(mfn_opts_get('header-action-title'), mfn_allowed_html('button')) .'</a>';
And I need to attach the following Analytics event tracker code:
onclick="gtag('event', 'clic', { 'event_category': 'EVENTCAT', 'event_label': 'EVENTLABEL'});"
Sounds not too hard, but im not managing to make this work, after I have tried a lot of different combinations.
Is there any way to just escape everything?
Try this please
echo '<a
onclick="gtag(\'event\', \'clic\', { \'event_category\': \'EVENTCAT\', \'event_label\': \'EVENTLABEL\'});"
href="'. esc_url($action_link) .'"
class="action_button'. esc_attr($action_class) .'" '. wp_kses_data($action_target) .'>'.
wp_kses(mfn_opts_get('header-action-title'), mfn_allowed_html('button'))
.'</a>';
In my PHP I have a line of JSON:
echo '"jsoncaption":"'.$xxx.' '.$yyy.' <br /> ('.$zzz.')",';
I want to have the text line-height: 110%;, so I do this:
echo '<div style=\'line-height: 110%;\'>';
echo '"jsoncaption":"'.$xxx.' '.$yyy.' <br /> ('.$zzz.')",';
echo '</div>';
But this causes an an error in my JS console!
Unexpected token < in JSON at position 55
Without the <div> everything works, but I want to use line-height.
Someone have an idea?
echo '"jsoncaption":"' . '<div style=\'line-height: 110%;\'>' . $xxx .' '.$yyy.' <br /> ('.$zzz.')</div>",';
What did I do?
This would be a more detailed script:
$content = $xxx.' '.$yyy.' <br /> ('.$zzz.')';
$wrapped_content = '<div style=\'line-height: 110%;\'>' . $content . "</div>";
echo '"jsoncaption":"' . $wrapped_content . '",';
EDIT: Untested of course, maybe some quotation marks are wrong...
I have this PHP file:
foreach($allfiles as $file) {
echo '<div class="file" id="file' . $file->id . '">';
echo '<div id="checkbox"><img src="images/delete.png" width="15" height="15"></img></div>';
echo '<div id="filename">'. $file->name . '</div>';
echo '<div id="size">| '. $file->size . ' </div>';
echo '<div id="created">'. $file->created . '</div>';
echo '<div id="download"><img src="images/download.png" width="18" height="18"></img></div>';
echo '</div>';
?>
<script>
var id = <?php echo $file->id; ?>
</script>
<?php
}
and this JS file
$('#file' + id).dblclick(function() {
alert(1);
});
What I'm trying to do is that when div "file" + the file id is clicked, it will alert "1" (or open the file).
The problem is that now it only alerts 1 when I doubleclick the last div I have, while it is supposed to be done on all of them.
Is there a solution like foreach div called file + something do ? when doubleclicked.
Sorry if this was very unclear :D
You can use data-* prefixed custom attribute like
echo '<div class="file" data-id="' . $file->id . '">';
Bind your event using the common class and then fetch data-idusing .data()
$('.file').on('dblclick', function() {
alert($(this).data('id'));
});