开发者

Redirecting in FF when I enter some page, can I prevent it with some javascript code?

开发者 https://www.devze.com 2023-04-11 02:08 出处:网络
The problem is as follows. When I enter to some page from my site clicking the link (FF browser), I am redirected to an unwanted site. 开发者_如何学Go

The problem is as follows. When I enter to some page from my site clicking the link (FF browser), I am redirected to an unwanted site. 开发者_如何学Go And some window pops-up where you can choose whether to stay or leave the site. When you click I want to stay, the window pops-up over again. This happens because the site have built in the following script:

var exit=true; window.onbeforeunload = function () {

var goto_url = 'http://some site'; if(exit==true){

exit=false; window.location.replace(goto_url);

return " Special Offer: Get 2 For 1 Price!"; } }

This not happens when I use IE8 browser, then everything is all right. Is there possible any solution in javascript code? Otherwise, can I block unwanted redirecting when enter to external site. I thing this must be some bug associated with FF browser.

Can somebody Help me with this problem, because I tried to find solution everywhere wihtout no luck.

thanks


This cannot be done strictly through JavaScript, since Firefox doesn't have a native way to intercept another web site's JavaScript on loading.

That said, there is another option that may work for you, even simpler than writing your own JavaScript:

http://www.bala-krishna.com/how-to-block-website-redirection-from-firefox-browser/ First, I'd recommend trying this link, and verifying your setting is set. This will probably already be checked off, and if so, unchecking it won't help. But if not, try enabling this field first and see if that help.

If not, you could try this Firefox extension: https://addons.mozilla.org/en-US/firefox/addon/noredirect/

It will allow you to block all sites' redirects, or only specific ones you choose.


Ok, there is "Grease Monkey" extention working for those who got installed that extention. I need to prevent redirect for all user that will click into the link (on my site) which is lead to external site. This problem is more much complicated. I believe there is any solution for this. For example, this script makes it impossible to redirect after clicking on the link to the external site. User just stay on my site when the external site try do redirect.

var prevent_bust = 0 window.onbeforeunload = function() { prevent_bust++ } setInterval(function() { if (prevent_bust > 0) { prevent_bust -= 2 window.top.location = 'my site.html' // replace your iframe with link to it } }, 1)

So it is possible to control somehow behavior of the external site. Now I need some modification in this script,which makes instead redirection to unwanted site, allow me to reach right one.

One more thing. The problem is that the site with this script,

> var exit=true; window.onbeforeunload = function () {
> var goto_url = 'http://some site';
> if(exit==true){
> exit=false; window.location.replace(goto_url);
> return " Special Offer: Get 2 For 1 Price!"; } }

shouldn't redirect when I enter the site, but when I leave her. So I'm not understand this behavior, but I need to do something, just hack this somehow.


Can you give me some exemple of code which can prevent javascript injection. I care very about this particular advertiser. Maybe I sould open an external site inside frame or somethnig. Maybe there must be some php script. There must be a way to resolve the problem like this. Impossible is possible any way.

I found a view codes on internet but don't know how it's working.

for exemple:

1.

<script type="text/javascript">
if(top != self) {
top.onbeforeunload = function() {};
top.location.replace(self.location.href);
}
</sript>

2.

<script type="text/javascript">
var prevent_bust = 0  
var id = setInterval(function() {  
if (prevent_bust > 0) {  
prevent_bust -= 2  
window.top.location = 'somesite_com.htm';  
}  
}, 1)                 
window.onbeforeunload = function() { prevent_bust++ }  
window.onclick = function() { clearInterval(id)}
</script>

3.

<script type="text/javascript">
<!-- 
if (parent != self  && !/^http:\/\/((www\.)|())somesite\.host>
\.com/.test(top.location.href))
top.location.replace(self.location.href);
// -->
</script>

4.

<script>
javascript:void(d=document);if(frames.length){alert('Script%20doesn/'t%20work%20in%20frames');}
else{while((el=d.getElementsByTagName('script')).length){el[0].parentNode.removeChild(el[0]);};onerror=function(){};d.close();}
</script>

So any more suggestions. Thanks for interesting.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号