How to use window.location in echo using php code
I need help using window.location=
to echo
using PHP
. Here is my code:
echo
'<div class="adsa">
<div class="adimg125" style="'.$stylea.'">
<div onclick="event.cancelBubble=true;if (event.stopPropagation) event.stopPropagation(); window.location='.$url.'" class="check" style="'.$check.'">Check Monitors</div>
</div>
</div>';
My data showing fine but link not working means it is not showing in '' to open link. Here is my data that is displayed
<div class="check" onclick="event.cancelBubble=true;if (event.stopPropagation) event.stopPropagation(); window.location=/index.php?key=perfectdeposit.biz" style="background: #767a81 none repeat scroll 0 0; color: white; cursor: pointer; display: none; font-size: 13px; padding: 2px 0 3px; position: relative; text-align: center; top: -132px; width: 117px; margin-left: 38px">Check Monitors</div>
You can see what is not showing here '' in this line
window.location=/index.php?key=perfectdeposit.biz
he needs to show it as
window.location='/index.php?key=perfectdeposit.biz'
+3
source to share
2 answers
It looks like you need to avoid these characters in PHP. Maybe something like this?
echo'<div class="adsa"><div class="adimg125" style="'.$stylea.'">
<div onclick="event.cancelBubble=true;if (event.stopPropagation) event.stopPropagation(); window.location=\''.$url.'\'" class="check" style="'.$check.'">Check Monitors</div>
</div></div>';
Pay attention to \
next to window.location
.
Here's the result:
$stylea = 'something';
$url = 'http://google.com';
$check = 'test';
<div class="adsa"><div class="adimg125" style="something">
<div onclick="event.cancelBubble=true;if (event.stopPropagation) event.stopPropagation(); window.location='http://google.com'" class="check" style="test">Check Monitors</div>
</div></div>
+2
source to share
I usually use heredoc to avoid quote errors, that is:
echo <<< EOF
<div class="adsa"><div class="adimg125" style="$stylea">
<div onclick="event.cancelBubble=true;if (event.stopPropagation) event.stopPropagation(); window.location='$url' class="check" style="$check">Check Monitors</div>
</div>
EOF;
Output:
<div class="adsa"><div class="adimg125" style="some_style">
<div onclick="event.cancelBubble=true;if (event.stopPropagation) event.stopPropagation(); window.location='/index.php?key=perfectdeposit.biz' class="check" style="something">Check Monitors</div>
</div>
0
source to share