Javascript窗口.打开在新窗口和同一窗口中打开目标URL
Javascript Window.Open Opens the Target URL in Both a New Window and the Same
基本上,我有一个带有社交媒体分享按钮的页面。它们中的一些正常工作(它们在一个新窗口中打开),然而,其他的在一个新窗口和同一个窗口中打开。我已经为这件事疯了一天了,但我似乎找不到解决办法。
参考页面:http://www.inetsolutions.org/gsa-search-engine-ranker-ultimate-tutorial-and-genuine-review-seo-software-of-the-gods/
正常工作的链接(Facebook, Twitter, Pinterest):
<a href="javascript:void(0)" class="ism_link" onclick="indeedPinterestPopUp(2513);ism_fake_increment('.pinterest_share_count', 'pinterest', 'http://www.inetsolutions.org/gsa-search-engine-ranker-ultimate-tutorial-and-genuine-review-seo-software-of-the-gods/');">
打开URL的链接,以便在新窗口和同一窗口中共享:
<a href="http://www.stumbleupon.com/badge/?url=http://www.inetsolutions.org/gsa-search-engine-ranker-ultimate-tutorial-and-genuine-review-seo-software-of-the-gods/&title=GSA%20Search%20Engine%20Ranker%20Ultimate%20Tutorial%20and%20Genuine%20Review%20%E2%80%93%20SEO%20Software%20of%20the%20Gods" class="ism_link" onclick="ism_fake_increment('.stumbleupon_share_count', 'stumbleupon', 'http://www.inetsolutions.org/gsa-search-engine-ranker-ultimate-tutorial-and-genuine-review-seo-software-of-the-gods/');return !window.open(this.href, '', 'width=700,height=575');">
我已经试过了:
- 我试图删除标签的"href"属性,并将URL字符串插入窗口。打开函数,而不是使用"this.href"。当我这样做时,链接只打开一个新窗口,但不会打开相应社交媒体的共享页面,而是打开目标URL。
- 我试图在非工作窗口后添加"返回false"。打开功能。
- 我也试图删除"ism_fake_increment"函数只是为了测试,但再次,无济于事。
- 我已经联系了插件作者,但他们要求访问我的网站内部,这是不会发生的。
任何想法都将非常感谢。感谢您的宝贵时间!
我建议您不要使用onclick
属性,因为它会导致极其混乱的代码。相反,在DOM中使用.addEventListener()
。
要禁用在同一窗口中打开链接的链接,只需禁用默认的even。这可以通过调用传递给回调的对象的.preventDefault()
方法来完成回调中的.addEventListener()
:
//Get our link:
var link = document.getElementById("stumbleupon");
//Bind the click event:
link.addEventListener("click", function(event) {
//Prevent the link from opening regularly with .preventDefault():
event.preventDefault();
//The following code with the plugin does not work because we haven't included the plugin in the code snippet, but as you can clearly see if you click the link, the link has clearly been disabled because of the above call to .preventDefault().
//Do different stuff with the plugin:
ism_fake_increment('.stumbleupon_share_count', 'stumbleupon', 'http://www.inetsolutions.org/gsa-search-engine-ranker-ultimate-tutorial-and-genuine-review-seo-software-of-the-gods/');
return !window.open(this.href, '', 'width=700,height=575');
});
<!-- Set the ID attribute so we can find this link in the DOM: -->
<a id="stumbleupon" href="http://www.stumbleupon.com/badge/?url=http://www.inetsolutions.org/gsa-search-engine-ranker-ultimate-tutorial-and-genuine-review-seo-software-of-the-gods/&title=GSA%20Search%20Engine%20Ranker%20Ultimate%20Tutorial%20and%20Genuine%20Review%20%E2%80%93%20SEO%20Software%20of%20the%20Gods" class="ism_link">Hello! This is a link to stumbleupon.com!</a>
相关文章:
- 按下一个HTML按钮,该按钮使用一个功能在同一个新窗口中打开URL
- asp.net MVC,重定向到视图,视图打开新窗口到外部url,它'It’’’’我们被当成一种风景
- javascript在退出时打开窗口url
- JavaScript 窗口.URL 在函数中未定义
- 如何从父窗口访问子窗口 URL
- 向右滑动一个图像,同时打开一个超时的新窗口url
- 如何使用javascript从父窗口获取子窗口url
- 更改每个不同选项卡的窗口URL
- 获取顶部窗口url从框架/iframe在不同的域
- 隐藏窗口.URL位置
- 当我们没有子窗口url时,如何知道子窗口已关闭
- 如何在弹出窗口url中使用具有$ sign的变量
- 在JSON中获取窗口url
- 保存当前窗口URL,并在几次导航后移回该URL
- 如何获取当前窗口URL并使用它
- Javascript新窗口URL中的回车/换行
- 如何从 Firefox 插件中的“编辑此书签”弹出窗口中获取窗口 URL
- 如何从Iframe获得父窗口URL
- 窗口.URL未定义
- Iframe表单提交数据到窗口URL