![](/img/trans.png)
[英]Javascript in anchor tag not working in FireFox and IE. Does work in Chrome
[英]Onclick not working in IE or Firefox but does work in Chrome
我正在嘗試讓Onclick在IE或Firefox中運行,但是無論如何,除了Chrome之外,我都無法正常工作。
<h2 onclick="javascript:window.location.href='<?php echo $cbox['read_more_url'];?>';" style="cursor: pointer;"><?php echo $cbox['title'];?></h2>
<img src="<?php echo $cbox['image']['sizes']['gallery_large'] ?>" height="<?php echo $cbox['image']['sizes']['gallery_large-height'] ?>" width="<?php echo $cbox['image']['sizes']['gallery_large-width'] ?>" alt="<?php echo $cbox['title']; ?>" onclick="javascript:window.location.href='<?php echo $cbox['title_url'];?>';" style="cursor: pointer;"/>
我也嘗試過location.href和window.location,但還是沒有。 這是網站http://www.tradewindgroup.com.au/該代碼引用了3個標題Construction-Plumbing-及其下面的圖片,在Chrome瀏覽器中工作正常。
謝謝
更新您的腳本:
<h2 onclick="redirectme('<?php echo $cbox['read_more_url'];?>');" style="cursor: pointer;"><?php echo $cbox['title'];?></h2>
<img src="<?php echo $cbox['image']['sizes']['gallery_large'] ?>" height="<?php echo $cbox['image']['sizes']['gallery_large-height'] ?>" width="<?php echo $cbox['image']['sizes']['gallery_large-width'] ?>" alt="<?php echo $cbox['title']; ?>" onclick="redirectme('<?php echo $cbox['title_url'];?>');" style="cursor: pointer;"/>
在javascrpt中創建如下函數:
function redirectme(myurl) {
window.location="http://" + myurl;
}
這是示例:
<html>
<body>
<h2 onclick="redirectme('google.com');" style="cursor: pointer;">Google</h2>
<script type="text/javascript">
function redirectme(myurl) {
window.location="http://" + myurl;
}
</script>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.