Reputation: 33
I need help for using window.location=
in echo
with 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 mean its not show in ' ' for opening link. Here is my data which 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 here is not show ' ' in that line
window.location=/index.php?key=perfectdeposit.biz
it's need to show like this
window.location='/index.php?key=perfectdeposit.biz'
Upvotes: 3
Views: 244
Reputation: 2290
Looks like you need to escape those 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>';
Notice the \
near the window.location
.
Here is the output:
$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>
Upvotes: 2
Reputation: 98871
I normally use heredoc to avoid quote errors, i.e.:
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>
Upvotes: 0