Html Onclick 刷新然后使用相同的点击 href ?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15345500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 06:20:17  来源:igfitidea点击:

Onclick refresh then href with the same click?

javascripthtml

提问by user2157989

I need a little help. I went div crazy on my site using a toggle class to hide and the divs in the middle of the page. Well a couple things first the website http://gregedisonproductions.com

我需要一点帮助。我在我的网站上使用切换类隐藏和页面中间的 div 疯狂。首先是网站http://gregedisonproductions.com

The first is if you click on things eventually especially on the leftsidebar they don't switch, and a bigger problem is if I'm watching a video from the leftsidebar and a play another one, it switch's but the audio keeps playing.

第一个是如果你最终点击东西,尤其是在左侧栏上,它们不会切换,而更大的问题是,如果我正在从左侧栏观看视频并播放另一个视频,它会切换但音频继续播放。

I was thinking that if the user clicked on anything, it would refresh the page, then execute the href command.

我在想,如果用户点击任何东西,它会刷新页面,然后执行 href 命令。

Can anyone help me in this area?

有人可以在这方面帮助我吗?

回答by aug

If you want to reload the page with href, you can try this

如果你想用href重新加载页面,你可以试试这个

<a href="#" onClick="window.location.reload();return false;">Reload</a>

Your problem though involves the fact that when you click on another video, it doesn't stop the original one; it simply hides it. Youtube has an APIthat allows you to stop the video through javascript though. I believe to pause a video you can do a pauseVideowith the API.

但是,您的问题涉及这样一个事实:当您单击另一个视频时,它不会停止原始视频;它只是隐藏它。Youtube 有一个API,允许您通过 javascript 停止视频。我相信要暂停视频,您可以使用 API执行pauseVideo

回答by Mollo

If you want to redirect the URL, just add this to your onclick event, using PHP:

如果您想重定向 URL,只需使用 PHP 将其添加到您的 onclick 事件中:

header("Location: http://yourpage.com/"); // add your URL  
exit;

Using Javascrip:

使用 Java 脚本:

window.parent.location = "http://yourpage.com/";